Below is an example HTML form one might use for a registration page.
<!DOCTYPE html>
<html>
<head>
<title>New user registration</title>
</head>
<body>
<form method="post" action="http://localhost/cgi-bin/register.cgi" enctype="application/x-www-form-urlencoded">
<fieldset style="display:none"><input type="hidden" name="new_user_registration" value="1" /></fieldset>
<p>Username:<br /><input type="text" size="50" name="new_registration_username" /></p>
<p>Password:<br /><input type="password" size="50" name="new_registration_password" /></p>
<p>Confirm password:<br /><input type="password" size="50" name="new_registration_password_confirmation" /></p>
<p><input type="submit" name="registration" value="Create My Account" /></p>
</form>
</body>
</html>
Notice the highlighted HTML code below (method="post"). This is where we define what method to use for sending variable/value pairs to the web server. In this situation, we are using the POST method.
<!DOCTYPE html>
<html>
<head>
<title>New user registration</title>
</head>
<body>
<form method="post" action="http://localhost/cgi-bin/register.cgi" enctype="application/x-www-form-urlencoded">
<fieldset style="display:none"><input type="hidden" name="new_user_registration" value="1" /></fieldset>
<p>Username:<br /><input type="text" size="50" name="new_registration_username" /></p>
<p>Password:<br /><input type="password" size="50" name="new_registration_password" /></p>
<p>Confirm password:<br /><input type="password" size="50" name="new_registration_password_confirmation" /></p>
<p><input type="submit" name="registration" value="Create My Account" /></p>
</form>
</body>
</html>
Notice the highlighted HTML code below (action="http://localhost/cgi-bin/register.cgi"). This line tells the web server where to send the variable/value data encoded in this form (i.e. the Uniform Resource Location or web address). In this case, we are sending it to localhost. Localhost is your the name of your own computer.
<!DOCTYPE html>
<html>
<head>
<title>New user registration</title>
</head>
<body>
<form method="post" action="http://localhost/cgi-bin/register.cgi" enctype="application/x-www-form-urlencoded">
<fieldset style="display:none"><input type="hidden" name="new_user_registration" value="1" /></fieldset>
<p>Username:<br /><input type="text" size="50" name="new_registration_username" /></p>
<p>Password:<br /><input type="password" size="50" name="new_registration_password" /></p>
<p>Confirm password:<br /><input type="password" size="50" name="new_registration_password_confirmation" /></p>
<p><input type="submit" name="registration" value="Create My Account" /></p>
</form>
</body>
</html>
If the form below is submitted to the web server running on localhost, four variables will be submitted:
<!DOCTYPE html>
<html>
<head>
<title>New user registration</title>
</head>
<body>
<form method="post" action="http://localhost/cgi-bin/register.cgi" enctype="application/x-www-form-urlencoded">
<fieldset style="display:none"><input type="hidden" name="new_user_registration" value="1" /></fieldset>
<p>Username:<br /><input type="text" size="50" name="new_registration_username" /></p>
<p>Password:<br /><input type="password" size="50" name="new_registration_password" /></p>
<p>Confirm password:<br /><input type="password" size="50" name="new_registration_password_confirmation" /></p>
<p><input type="submit" name="registration" value="Create My Account" /></p>
</form>
</body>
</html>
In the example form above, if we changed the method from POST to GET and then submitted the following form data to our localhost CGI application, register.cgi:
After the user presses the Create My Account button, the URL would look like this:
http://localhost/cgi-bin/register.cgi?new_user_registration=1&new_registration_username=rbruce&new_registration_password=super%20secret&new_registration_password_confirmation=super%20secret®istration=Create%20My%20Account
Note that in this long URL:
The variable/value pairs passed into register.cgi from the GET method are as follows:
VARIABLE | VALUE |
---|---|
new_user_registration | 1 |
new_registration_username | rbruce |
new_registration_password | super secret |
new_registration_password_confirmation | super secret |
registration | Create My Account |
Fall 2016, CS-160:
Lectures:
Assignments:
Handouts:
Programs: