Form Design
Forms processing is a very important feature of PHP. It is through the use of forms that users interact with your Web pages and through which you can collect information for personalizing pages for your visitors. In a broader information processing sense, forms provide for data entry into your processing systems. They are the primary mechanism for capturing the data that your scripts process to generate information, to update files and databases, and to respond to user requests for information output.
As you proceed through this tutorial, you will learn about all aspects of forms processing. We will have chances to discuss and demonstrate all of the controls, or data entry mechanisms, that can be coded on forms. You probably have encountered most of these in your meanderings across the Web: text entry fields, clickable buttons, radio buttons, checkboxes, drop-down menus, and the like. We will cover all of these in the following lessons. For now, we will consider a couple of common controls - text entry boxes and forms submission buttons.
An Example Application
This first example of forms processing is a login application. It consists of two pages. The first page, named "login.php," contains a form for submitting an account and password. The visitor enters this information and clicks the "Submit" button to submit the form information for checking.
The second page is a site welcome page named "welcome.php". The form information is submitted to this page for account and password checking. If the correct account and password is submitted, then the page is viewable as in the following figure. If either the account or password is incorrect, the visitor is returned to the login.php page.
Form Controls
login.php
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form name="login" action="welcome.php" method="post">
<fieldset>
<h3>Login Page</h3>
<table>
<tr>
<td>Account: </td>
<td><input type="text" name="account" value="John" size="10"></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" size="10"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submitButton" value="Submit"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
HTML form controls are displayed on a web page by coding them within <form>
...</form>
tags. These tags surround the form controls; however, they do not need to enclose them "tightly." In other words, the <form>
tags need not immediately precede the first control nor immediately follow the last control. If your page contains a single form, you can code the opening ")%>