Newbie question about "submit"

J

John Smith

I have a neophyte question regarding what really gets sent out once I
click a submit button in a form. For example,
(http://www.webcom.com/~webcom/html/tutor/forms/start.shtml)

< FORM METHOD=POST
ACTION="http://www.webcom.com/cgi-bin/form" >

Enter your name:
< INPUT NAME=your_name >
< INPUT TYPE=submit VALUE="Test this form" >
< /FORM >

Suppose I enter "John" into the name field and click on the button,
what exactly is the text that gets sent back to the server? I tried
"http://www.webcom.com/cgi-bin/form?John", but the server returns an
error message. I'd like to the correct syntax for this.

Also, in the case where a form contains multiple text fields, radio
buttons, drop lists, etc, what is the syntax for encoding all these
input that's submitted to the server? A link to an on-line tutorial
would be appreciated.
 
H

Hywel Jenkins

necm500 said:
I have a neophyte question regarding what really gets sent out once I
click a submit button in a form. For example,
(http://www.webcom.com/~webcom/html/tutor/forms/start.shtml)

< FORM METHOD=POST
ACTION="http://www.webcom.com/cgi-bin/form" >

Enter your name:
< INPUT NAME=your_name >
< INPUT TYPE=submit VALUE="Test this form" >
< /FORM >

Suppose I enter "John" into the name field and click on the button,
what exactly is the text that gets sent back to the server? I tried
"http://www.webcom.com/cgi-bin/form?John", but the server returns an
error message. I'd like to the correct syntax for this.

http://www.webcom.com/cgi-bin/form?your_name=John

Your form is using POST, so your script (/cgi-bin/form) may choke on the
GET you're typing into your browser.
Also, in the case where a form contains multiple text fields, radio
buttons, drop lists, etc, what is the syntax for encoding all these
input that's submitted to the server?

Why would you need to encode them - the browser will do that for you.

A link to an on-line tutorial
would be appreciated.

http://www.google.com/
 
S

Stan Brown

comp.infosystems.www.authoring.html, Hywel Jenkins

That's like saying "Library of Congress" when someone asks you to
recommend a book on the life and times of Gladstone.

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
 
T

Toby A Inkster

John said:
<FORM METHOD=POST
ACTION="http://www.webcom.com/cgi-bin/form">
Enter your name:
<INPUT NAME=your_name>
<INPUT TYPE=submit VALUE="Test this form">
</FORM>

Suppose I enter "John" into the name field and click on the button,
what exactly is the text that gets sent back to the server? I tried
"http://www.webcom.com/cgi-bin/form?John", but the server returns an
error message. I'd like to the correct syntax for this.

If it were a GET request (rather than a POST request) it would look like
this:

http://www.webcom.com/cgi-bin/form?your_name=John

But POST requests are different. The variables aren't tacked onto the URL
and are sent by other means. Find an HTTP tutorial for more details.
Also, in the case where a form contains multiple text fields, radio
buttons, drop lists, etc, what is the syntax for encoding all these
input that's submitted to the server?

Consider the following form:

<form action="myscript.cgi" method="GET">
<fieldset>
<legend>Personal Details</legend>
<label><input name="name1"> Given Name</label><br>
<label><input name="name2"> Family Name</label><br>
<label><input name="sex" value="m" type="radio" checked="checked">
Male</label>
<label><input name="sex" value="f" type="radio"> Female</label><br>
<label>
<select name="age">
<option value="range1">Under 18</option>
<option value="range2">18-25</option>
<option value="range3">26-35</option>
<option value="range4">36-49</option>
<option value="range5">50+</option>
</select>
Age
</label><br>
<label><input name="spam1" checked="checked" type="checkbox">
Sell my details to spammers</label><br>
<label><input name="spam2" type="checkbox">
Sell my details to <strong>evil</strong> spammers</label><br>
</fieldset>
</form>

If I fill in my name, choose "Male" from the radio buttons, choose my age
(I'm 23) and leave the checkboxes as they are, the following URL will be
submitted:

myscript.cgi?name1=Toby&name2=Inkster&sex=m&age=range2&spam1=on

Note: no "spam2=off" is submitted.
 
T

Toby A Inkster

Toby said:
<label><input name="spam2" type="checkbox">
Sell my details to <strong>evil</strong> spammers</label><br>
</fieldset>
</form>

.... and a "submit" button might have been nice. ;-)
 
H

Hywel Jenkins

comp.infosystems.www.authoring.html, Hywel Jenkins


That's like saying "Library of Congress" when someone asks you to
recommend a book on the life and times of Gladstone.

With Google, however, you can show the smallest hint of common sense and
type "form tutorial" and get pretty much straight to what you need, same
if you search for "life and times of Gladstone".
 
S

Stan Brown

comp.infosystems.www.authoring.html, Hywel Jenkins
With Google, however, you can show the smallest hint of common sense and
type "form tutorial" and get pretty much straight to what you need, same
if you search for "life and times of Gladstone".

And anyone who knows how to use a search engine already knows of the
existence of a search engine, so all your reply did was waste
bandwidth.

What Google (and the Library of Congress) won't tell you is which
source is better than another. That would have been worth
mentioning; otherwise better to keep silent.

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
 
J

John Smith

Toby A Inkster said:
If it were a GET request (rather than a POST request) it would look like
this:

http://www.webcom.com/cgi-bin/form?your_name=John

But POST requests are different. The variables aren't tacked onto the URL
and are sent by other means. Find an HTTP tutorial for more details.

Thanks for the tips, but
"http://www.webcom.com/cgi-bin/form?your_name=John" doesn't work,
guess it must use POST then.

I briefly looked up the dif between "get" and "post", it seems that
the latter doesn't encode submission in url form, which begs the
question: how does it send data anyway? what data does it actually
send? in encrypted form? do the data fromat differs from one form from
another depending on the specific implementation of the programmer?
Can one glean some hints by examining the html code of the submission
page?

The reason I'm interested is that I'm curious about if it's possible
to automate the submission process by directly sending requests to the
remote server so that no human is needed to click the "submit" button
for every submission. It'd be very neat if I can do this even with
forms using "post".

Thanks again for the help.
 
E

Eric Bohlman

(e-mail address removed) (John Smith) wrote in
I briefly looked up the dif between "get" and "post", it seems that
the latter doesn't encode submission in url form, which begs the
question: how does it send data anyway? what data does it actually
send? in encrypted form? do the data fromat differs from one form from
another depending on the specific implementation of the programmer?
Can one glean some hints by examining the html code of the submission
page?

No. In order to understand the difference, you need to understand how HTTP
requests work. Teaching that is rather beyond the scope of a Usenet post,
but there are plenty of tutorials available if you know that what you're
looking for is the details of the HTTP protocol.

In a nutshell, the difference is that a GET request is made to the URL
specified in the form's action with the parameters appended to it as part
of a query string (which begins with a question mark), whereas a POST
request is made to the unadorned URL, and the parameters are sent as part
of the body of the request. That won't make much sense to you until you
get somewhat familiar with HTTP.
The reason I'm interested is that I'm curious about if it's possible
to automate the submission process by directly sending requests to the
remote server so that no human is needed to click the "submit" button
for every submission. It'd be very neat if I can do this even with
forms using "post".

Yes, that can be done quite easily. If, for example, you were doing it in
Perl, you'd want to use the LWP::UserAgent module, which internally
understands the differences between the two requests and handles them
appropriately. Other languages have similar libraries/modules, and you
would be *strongly* advised to use them rather than trying to do everything
yourself at the TCP level; there are lots of tricky aspects to what looks,
on the surface, like a simple protocol, and the authors of those libraries
have already dealt with them and tested their code. This is one wheel that
should not be reinvented.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top