PHP HTML Forms

In this chapter you will learn:

  1. What is a HTML form
  2. Example - an example form
  3. Form attributes
  4. Example - Create an HTML Form

Description

An HTML form is a collection of HTML elements embedded within a page. By adding different types of elements, you can create different form fields, such as text fields, pull-down menus, checkboxes, and so on.

Example

All Web forms start with an opening <form> tag, and end with a closing </form> tag:


<form action="myscript.php" method="POST">  
     <!-- Contents of the form go here -->  
</form>  

Form attributes

There are two attributes within the opening <form> tag:

  • action - tells the browser where to send the form data. This should either be an absolute URL or a relative URL.
  • method - tells the browser how to send the form data. You can use two methods: GET is for sending small amounts of data and makes it easy for the user to resubmit the form, and POST can send much larger amounts of form data.

Example 2


<form action="someform.php" method="post">
  Name: <input type="text" name="Name" value="Jim" /><br />
  Password: <input type="password" name="Password" /><br />
  Age: <input type="text" name="Age" /><br />
  <input type="submit" />
</form>//from   j  av a  2 s  .  co m

Next chapter...

What you will learn in the next chapter:

  1. GET POST Superglobal Array
  2. Example - Accept value from $_GET and $_REQUEST
  3. Different between GET and POST
Home » PHP Tutorial » PHP Form
PHP HTML Forms
PHP GET and POST
PHP Form Elements
PHP Form TextField
PHP Form Password Field
PHP Form Textarea
PHP Form CheckBox
PHP Form Select
PHP Form RadioButton
PHP Form Submit
PHP Form Reset
PHP Form Push Button
PHP Form Image
PHP Form Hidden Field
PHP Split Form Across Pages
PHP Form Validation
PHP Form File Upload
PHP Form Demo
PHP Form Empty Fields
PHP Form Multi-Value Fields
PHP Redirect after a Form Submission