Designing a Form

A "form" on the Web is considered to be zero or more form elements, plus a submit button. These forms are designed to electronically replicate the forms we've all filled in hundreds of times before in real life—signing up for a bank account, a passport, etc. You start your form using the <form> HTML tag, and you end with </form>. By separating forms like this, you can have multiple forms on one page.

Given the above definition, here is the most basic form in HTML:

    <form>
    <input type="submit" />
    </form>

That will simply show a button with "Submit" written on it, which will not submit any data when clicked. Figure 9-1 shows how it looks in Konqueror running on Linux:

The most basic form is just a Submit button by itself

Figure 9-1. The most basic form is just a Submit button by itself

There are two attributes to the <form> tag that you should be aware of and use: action and method. Action sets the location of the page that will handle the results of the form—the place where the variables should be sent. Method describes how the data should be submitted, and you have two options: GET and POST.

GET and POST

When defining the method a web browser should use to send variables to the page specified by your action, you either use GET or POST. Both send variables across to a page, but they do so in different ways.

GET sends its variables in the URL of your visitors' web browsers (shown in Figure 9-2), which makes it easy to see what ...

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.