Le 4 mai 2021, la plateforme Yahoo Questions/Réponses fermera. Elle est désormais accessible en mode lecture seule. Aucune modification ne sera apportée aux autres sites ou services Yahoo, ni à votre compte Yahoo. Vous trouverez plus d’informations sur l'arrêt de Yahoo Questions/Réponses et sur le téléchargement de vos données sur cette page d'aide.

justme
Lv 7
justme a posé la question dans Computers & InternetProgramming & Design · il y a 4 ans

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?

Mise à jour:

<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>

Mise à jour 2:

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!

Mise à jour 3:

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.

Mise à jour 4:

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!

3 réponses

Pertinence
  • Anonyme
    il y a 4 ans
    Réponse favorite

    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

  • cpcii
    Lv 7
    il y a 4 ans

    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.

  • Chris
    Lv 7
    il y a 4 ans

    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.

Vous avez d’autres questions ? Pour obtenir des réponses, posez vos questions dès maintenant.