HTML Form Controls


As you already know, HTML form controls are used to obtain user input. We played with HTML form controls using JavaScript, but we couldn't do much with the data entered in the controls. Now, we get to pass the form control data from page to page.

This assignment will allow you to use various types of form controls such as text fields, password fields, text areas, check boxes, and radio buttons. You will input data and pass the data to another page.

Remember that all controls should be included within the <form> tag. The <form> tag should include a method attribute and an action attribute. In addition the <form> tag should include submit and reset buttons.

Here's an example of a form which includes a text field control:

<form name="form" method="post" action="ProcessTextField.php">
<h1>Text Field </h1>
What is your name?: <input name="txtname" type="text" size="25" maxlength="25">
<br / ><br / >
<input name="submit" type="submit" value="Submit">
<input name="reset" type="reset" value="Reset">
</form>

Notice that the action attribute is set to 'ProcessTextField.php'. This means that, upon hitting the submit button, all form data is sent to the 'ProcessTextField.php' page. The data is actually sent with an array variable named $_REQUEST.

$_REQUEST holds all values submitted on a form. If you have ten form controls on a form, you will have ten values in the $_REQUEST array. This is create automatically.

Once the form is submitted, the 'ProcessTextField.php' page is responsible for processing the form data. For example, you can get the value of the above text field by using the $_REQUEST array variable. The following code prints the message sent through the form control:

Your name is:<?php print($_REQUEST["txtname"]);?>

 

Here are additional control examples linked to their respective process pages:

  1. Text Field
  2. Password Control
  3. Text Area
  4. Check Box
  5. Radio Buttons
  6. Drop-Down Box
  7. List Box
  8. All Controls - Using ($_REQUEST["controlname"])
  9. All Controls - Using a ForEachLoop