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 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="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.

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.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: GET and POST >>

Previous chapter: What does it mean to be dynamic?

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.