How do I send text from a textbox from the web page to the server?

I can but if the text has a & or = in it the server does not get the full value.
Example:
the textbox has a name of "name" and the value in the text box is "notme&myname=justme"

When submitted the string is:
name=notme&myname=justme

This looks like two key/value pairs to the server so the name value becomes notme instead of the entire text box value. How can I send the entire value entered? Is there a way to put the value in quotes or something?

2017-09-08T00:14:50Z

<form id="id-form" action="id.cgi" method="post" target="id-response">
<div class="text-input">
<label for="name">Name:</label>
<input type="text" id="name" name="name" maxlength="60">
</div>
<div class="text-input">
<label for="id-num">ID#:</label>
<input type="text" id="id-num" name="id-num" maxlength="60">
</div>
<div class="form-button">
<button name="save-id" id="save-id" class="save-button" type="submit">Save</button>
</div>
</form>

2017-09-08T02:30:07Z

Guys,
When I do as you say the value is "notme" not "notme&myname=justme" because when the string is parsed the & character separates the key/value pairs. In the example the & and = should be part of the value, not a different key/value. That's the problem!

2017-09-08T02:37:46Z

Using the example HTML above:
If I enter in the Name box noname&myname=justme
And in the ID# box 12345
The page sends:
name=notme&myname=justme&id-num=12345
When the server parses the string it gets 3 key/value pairs
name=notme
myname=justme
id-num=12345
What I want is 2 key/value pairs somehow
name=notme&myname=justme
id-num=12345

The problem is not the server side, its the way its sent from the web page.

2017-09-08T20:19:54Z

OK, I must have been going nuts. The string from the page was fine, the & and = were encoded. The server side was decoding and saving the values properly. The problem was the server, when sending OUT the values to the page was not encoding them, and even if it were, the page was not set up to decode the values. THAT was were my problem was.

Thanks for the answers though!

Anonymous2017-09-08T07:13:19Z

Favorite Answer

Hey guys, the key to the problem is he's POSTing to a CGI on the backend (as evidenced by the parameter action="id.cgi" in the FORM)

Escaping the special characters is the problem (which is why CGI is discouraged as a backend - typically with PHP a preferred solution.)

A possible solution can be found here: http://www.perlmonks.org/?node_id=695172

You can also use Javascript's escape() function prior to POST .submit() to transform the special characters on the front end so you can use the usual parser on the CGI backend (but then you have to figure out how to unescape those characters on the backend - and how to do that depends on what you're using on the CGI backend.)

If forced to use CGI, I always prefer Python. But in most cases, that's like killing flies with a cannon. As a result, many CGI back-ends tend to be perl since it's much lighter for straight text processing.

If I recall correctly, the O'Reilly book on HTML recommended *against* using CGI if you can avoid using it. ASP, JSP, PHP, almost anything else is preferable - esp since CGI can become a major security hole if you put too powerful a processing capability behind it (like Python) XD

cpcii2017-09-08T00:39:35Z

In your server side script you do something like local_variablename = $_Post['TEXTBOX_NAME']; And then do something with it, if your using VB its similar variablename = request.querystring['textbox_name']; All languages work this way in some form or another, look it up in your language.


You have to URL encode the keyword/pair. if you try and pass a & through the URL string the server parses it to be a separate value. The way a server is PROGRAMMED to work is to split everything on & so if you pass 3 &'s through the URL you get three key/pair values.

If you want to send a & as part of a value you have to encode it. Look up encoding that through browser first.

Chris2017-09-07T23:50:27Z

You can send it using POST instead.
Just add
method="post"
to the <form> tag.

On the server, check $_POST instead of $_GET (if you're using PHP)

Edit:
Right, I didn't realize that post parameters are parsed the same way. Just replace & with &amp;, them revert that on the server.