Set URL path segments with form inputs via URL template variables



I was wondering what you might think about being able to use URL templates in forms. The basic idea would be that instead of submitting query variables and values as (get) or as entity bodies (post), inputs could be used to target path segments?

Something like:

<form action-template=“{foo}”><input name=“foo”>…</form>

on submit could process the action-template value and substitute input variables into that string at appropriate locations.

Is there an existing way to do this in HTML?

This could be useful for targeting server APIs, and possibly other things.

Cheers, Peter


{ could be part of a URL itself. So how would you know whether it needed to be replaced or not? This would then introduce an escaping context to HTML which isn’t done anywhere else as far as I know (outside of regex patterns for validation of form inputs.)

I’d like to know what the situation is that would require this kind of structure. It seems like everyone has gotten along just fine without front-end URL parameter substitution thus far.


I don’t think the {} characters are legal URL characters. I was thinking that another attribute might be used instead of action, that was a known location to be processed on submit to substitute form variables into template variables. The result could be used as the action value.

I think it could be useful for accessing REST APIs. Someone else had the issue here


{ needs to be encoded. However browsers will do that automatically if needed.

However, a curly brace in a query parameter is also allowed just fine. So if people try to use this in a query option, it would need some extra mechanism to specifically say in any given case that a brace would need to be replaced with the name.

IMO the SO post linked to is a poorly designed form interface. Not something that demands an addition to browser engines.


There is an existing specification for URL templates, which I think could be sampled to drive the data model and processing of the (hypothetical) action-template attribute.

Also, your server design is your business. People design their URLs to have meaning for themselves/ their customers and it’s not really others’ job to say what is best for them, even browser engines I imagine. For example, here’s another question which refers to a hypothetical server’s action path: /books/{book_id} which seems reasonable to me.

Clearly what we’re discussing can be and is solved by scripting. My question is about HTML though.


I’m not sure how I feel about this, but what about using `-quoted template strings for this, e.g. action=`/example/of/path/mapping/${this.fields.segments.value}` and using script execution to evaluate the template and submit the form?


I think we should get back to basics of requests, use cases. Use cases take precedent. Please provide a real-world use-case where an action template system solves a problem that is otherwise difficult or impossible to solve.