When using the 'get' method for form,
<form action="domain.com" method="get">
Surname: <input type="text" name="ABC"><br>
Name: <input type="text" name="DFG"><br>
<input type="submit" value="Submit">
</form>
the input will be sent to a page on the server called
domain.com/?ABC=surname&DFG=name
My question: how to edit the form to make it such that the input gets sent to a page called
domain.com/?ABC="surname"&DFG="name"
(notice the " " around the two inputs.
Please advice. Thanks!
I believe you are looking for the quotation mark character (U+0022) which is not allowed in plain text it must be encoded as %22.
I did some javascript to add the doublequotation mark characters to your input from the user, and then it should submit the form action as before.
<script type="text/javascript">
beforeSubmit = function(){
var abc = document.getElementById("ABC").value;
document.getElementById("ABC").value = "%22" + abc + "%22";
var dfg = document.getElementById("DFG").value;
document.getElementById("DFG").value = "%22" + dfg + "%22"; //changes input field value
document.getElementById("formid").submit(); //submits the form
}
</script>
<form action="domain.com" method="get" id="formid">
Surname: <input type="text" name="ABC" id="ABC"><br>
Name: <input type="text" name="DFG" id="DFG"><br>
<input type="button" value="Click" onclick="beforeSubmit();" />
</form>
Why do you need to have these in quotes?
The website in the form GET
should be able to understand the form inputs you're sending to it without the quotes. If you really need to add quotes (or anything else to the form input), you can do it using jQuery.
Something like
$("form").submit(function(event) {
$.get('domain.com', { name: ..., surname: ...});
event.preventDefault();
});
See:
http://api.jquery.com/jquery.get/
EDIT: more info:
I don't have enough reputation to comment, so I'll extend what the other commenter did here. He's almost right, except instead of "%22" you need to add the quotation character ("), and it'll encode it for you. The reason it adds %25 is that its actually encoding the percent (%) character! :D
Modified from Beau Bouchard's answer:
function (){
var abc = document.getElementById("ABC").value;
document.getElementById("ABC").value = "\"" + abc + "\"";
var dfg = document.getElementById("DFG").value;
document.getElementById("DFG").value = "\"" + dfg + "\""; //changes input field value
document.getElementById("formid").submit(); //submits the form
}