Paul
Paul

Reputation: 26650

HTML form to generate an URL with special character and prefix between parameter name and value

Could an ordinal HTML form that generates a GET request, produce such an URL without JavaScript?:

http://servername/urlpart1/#/urlpart2?id=Prefix-139

where http://servername/urlpart1/#/urlpart2?id=Prefix- is constant and 139 ist an <input name="id" /> value.

I could achieve only the URL generation:


<form action="http://servername/urlpart1/urlpart2">
  <input name="id" />
  <input type="submit" />
</form>

Update

I ended up with building a small desktop Windows application where I can do whatever I want.

Upvotes: 0

Views: 545

Answers (2)

critical_error
critical_error

Reputation: 6706

I don't believe there is any way to manipulate the action URL without using JS, however, you could require the "Prefix-" as part of your "id" field's pattern.

Try something like this:

<form action="http://servername/urlpart1/#/urlpart2" method="GET">
    <input name="id" value="Prefix-" pattern="Prefix-+[0-9]{1,}" title="Prefix-{number}." />
    <input type="submit" />
</form>

My pattern example requires the string "Prefix-" followed by at least 1 numeric value.

Upvotes: 1

edddd
edddd

Reputation: 482

As a workaround, you could add the value attribute to <input name="id"> and give it the value Prefix-, so the user could just type in the value after it. Maybe also use some pattern matching and display an error if the user deleted that piece of text. The below code only shows adding the value attribute, not the pattern matching.

<form action="http://servername/urlpart1/#/urlpart2">
  <input name="id" value = "Prefix-" />
  <input type="submit" />
</form>

Upvotes: 1

Related Questions