- Sending data to the server
- Creating forms
- GET request - parameters are included in the query string
portion of an URL and passed in the request line
- POST request - parameters are sent as the content
of the HTTP request
- POST requests are typically generated by a form
- Here is an example of a form
<h1>Mailing List Registration</h1>
<p>Please fill out this form to be notified about updates.
<form action="register.cgi" method="POST">
<p>
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email">
<hr>
<input type="submit" value="Register">
</form>
- Run the example
- When this form is submitted, the browser encodes the three
form elements as:
name=Joe+Cool&email=snoopy%40peanuts.com
- ACTION
Specifies the URL of the CGI script that should receive and
process the HTTP request (defaults to current URL)
- METHOD
Specifies the HTTP request method used to call the CGI script
(defaults to GET)
- onSubmit
A JavaScript handler, and specifes the JavaScript code
that should be executed when the form is submitted
<form action="http://sigma10:8000/~weiss/login.cgi"
method="GET">
<table>
<tr>
<td>User:
<td><input type="text" name="user">
<tr>
<td>Password:
<td><input type="password" name="secret">
<tr>
<td><input type="submit" value="Login">
</table>
</form>
Run the example
<form action="http://sigma10:8000/~weiss/rate-movies.cgi"
method="POST">
Pick your favorite movie(s):
<p><input type="checkbox" name="movie"
value="paris">Paris Texas
<p><input type="checkbox" name="movie"
value="portrait">Malena
<p><input type="checkbox" name="movie"
value="beauty">American Beauty
<p><input type="checkbox" name="movie"
value="big">Big Chill
<p><input type="submit" value="Continue">
</form>
Run the example
<form action="http://sigma10:8000/~weiss/schedule.cgi"
method="POST">
Which day do you want to meet?
<p><input type="radio" name="day"
value="mon">Monday
<p><input type="radio" name="day"
value="tue">Tuesday
<p><input type="radio" name="day"
value="wen">Wednesday
<p><input type="submit" value="Book Appointment">
</form>
Run the example
- Submits the contents of the form to the server
- When the user clicks on a submit button, the browser
- executes any associated onSubmit handler
- formats an HTTP request according to the form method and encoding type
- sends this request to the URL in the form action
- Syntax for a submit button:
<input type="submit" name="submit_button" value="Submit the Form">
- VALUE
Specifies both the label of the button and the value of this element when
the form is submitted
- onClick
JavaScript handler executed when the user clicks the button; returning false
from this handler cancels the submit
- A form can have multiple submit buttons
- Only the name and value of the submit button clicked will be included
in the request
<form action="http://sigma10:8000/~weiss/account.cgi"
method="POST">
<p>You have the following options:
<p><input type="submit" name="action" value="Add">
<p><input type="submit" name="action" value="Delete">
<p><input type="submit" name="action" value="Cancel">
</form>
- Run the example
<form action="order.cgi" method="GET">
<input type="image" src="images/cake.jpg" name="choice">
</form>
Run the example
See the output
- The <select> tag is used to create a list of options
- This list can be displayed in two ways:
- a (pulldown) menu
- a scrolling box
- SIZE
Determines number of lines visible in the list
- MULTIPLE
Allows user to select multiple values
<form>
Choose a search engine:<br>
<select name="search" size="1">
<option value="excite">Excite
<option value="yahoo" selected>Yahoo
<option value="altavista">AltaVista
<option value="hotbot">HotBot
</select>
</form>
Run the example
<form>
Choose the news channels you want to subscribe to:<br>
<select name="news" size="3" multiple>
<option value="business">Business
<option value="national">National
<option value="international">International
<option value="sports">Sports
<option value="features">Features
</select>
</form>
Run the example