Hudzilla.org - the homepage of Paul Hudson
Contents > HTML Forms Wish List | Report Bug | About Me ]

7.3     Designing a form

This is NOT the latest copy of this book; click here for the latest version.

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 therefore 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>

What does it do? Well, very little, really - it will simply show a button with "Submit Query" written on, which will not submit any data when clicked. The screenshot below is how it looks in Konqueror running on Linux:



There are two key 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.





<< 7.2 What does it mean to be dynamic?   7.3.1 GET and POST >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
d@aerno.com - 20 Aug 2008

Technically though, you don't need a submit button to cause an action.

Suck My Willy - 20 Aug 2008

I need pre written scripts in dumb

rolo@irolo.net - 20 Aug 2008

"Since HTML 4 you can use the button tag for buttons."

Although this is true, the SUBMIT TYPE is a special kind of BUTTON that hides the work of processing a FORM. If you are using PHP and you have set the ACTION of the FORM to a PHP page, like so:

<FORM METHOD="POST" ACTION="sendmail.php">
<INPUT TYPE="SUBMIT">
</FORM>

Then any values in the form will be sent to sendmail.php, without having to write any more code. There is also a RESET TYPE with built-in functionality.

Shadow - 20 Aug 2008

The code:
<FORM>
<INPUT TYPE="submit" />
</FORM>
Could be used as:
<form>
<INPUT TYPE="submit">
</form>

dho - 20 Aug 2008

Since HTML 4 you can use the button tag for buttons.

A PHP User - 20 Aug 2008

jimn



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is six plus nine?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow