Javi González Javi González - 8 months ago 41
HTML Question

HTML GET form passing + symbol as %2B

I'm coding a form to send a GET request with the parameters selected by the user in the form. In one of these fields, the user has to select a package which value have a + symbol. This is a piece of the form:

<form name="creahost" method="get" enctype="application/x-www-form-urlencoded" action="*********.php">

<input type="radio" name="setupName" value="Mail+1GB+15boxes" checked> Mail 1GB | 15 boxes</input><br>

When the submit button is pressed and the GET request is sent to the server, the URL is like this:

How can I tell to the browser that the URL it is composing has to be with + instead of %2B?

Thank you!


%28 is how you represent a plus sign in a URL. A literal + would be decoded as a space.

It sounds like your real problem is that your server side code is not handling URLs properly and failing to decode percent encoded characters. You should address the problem there.

If you really wanted to force this client side (which is a terrible idea) then you'd have to rebuild the entire form processing procedure in JavaScript.

YourForm.addEventListener("submit", submit_with_improper_plus_encoding);

function submit_with_improper_plus_encoding(event) {
    var form = this;
    var query = "";
    for (var i = 0; i < elements.length; i++) {
         var el = elements[i];
         if (el.disabled) {
         if (el.name == "") {
         if ((el.type == "checkbox" || el.type == "radio") && !el.checked) {
         query += encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value) + "&";
    query = query.replace(/%2B/g, "+")
    location = "*********.php?"+ query;

The above doesn't account for correctly including the data from the clicked submit button.