jump to navigation

working with HTML forms September 29, 2008

Posted by Nsh15 in Common PHP Applications, HTML, php.
Tags: , , ,
1 comment so far

For a web page tp be active, it must collect information from the user. which is done using HTML forms.

Displaying HTML forms:

there is two ways to do that, u can write the HTML code directly or inside the echo statement, which gives the browser html sentences.

<form action = “page to open after click submit.php” method= “POST” >

<input type= “text” name= “field name” value = “default value to display“>

<input type= “text” name= “field name” value = “default value to display“>

<input type =”submit” value = “Submit button name“>

  • action: u write here the name of the page u want the user to go into after clicking the submit button
  • method: there r two ways of methods: POST and GET … i will talk about ‘em later in this blog
  • now, we start creating the fields using <input type=”text” which means that the field will be text field
  • name: the name of the field, will not be displayed, just to work with while taking information from it
  • value: this value will be written inside the field box at the beginning
  • now, to make the submit button, by putting the type = “submit”
  • value: this will be the text written over the button

Adding selection list:

<select name=”the list name“>

<option> “first option” </option>

<option> “second option” </option>

<option> “fthird option” </option>

</select>

Adding Radio Buttons:

<input type=”radio” name = “radio  name” value = “the value to be stored while receiving the info “> “text to display “

<input type=”radio” name = “radio  name” value = “the value to be stored while receiving the info “> “text to display “

Its important to use the same name for all radio options. otherwise it won’t work probably!

Adding check boxes:

<input type=”checkbox” name=”check box name” value= “value to be stored” > “text to display

<input type=”checkbox” name=”check box name” value= “value to be stored” > “text to display

Example:

<br><center><h2> Customer information </h2></center>
<br><br>

<center>
<table border=”0″>
<form action=”customer_info.php” method=”POST”>
<tr> <td> First name:</td> <td> <input type=”text” name=”first_name” value=”enter ur first name plz”></td></tr>
<tr> <td>Second name: </td> <td> <input type=”text” name=”second_name” value=”enter ur second name plz”> </td></tr>
<tr><td>Last name: </td> <td> <input type=”text” name=”last_name” value=”enter ur last name plz”></td> </tr>
<tr><td> Street Address:</td><td> <input type=”text” name=”st_address” value=”enter ur st address plz”></td> </tr>
<tr><td> City:</td><td>
<select name=”city”
<option> Amman </option>
<option> Aqaba </option>
<option> Irbd </option>
<option> Zarqa </option>
</td> </tr>
<tr><td>Sex: </td><td>
<input type =”radio” name=”Radio1″ value= “M” > Male
<input type =”radio” name=”Radio1″ value= “F”> Female
</td></tr>
<tr><td>Your Operating system: </td><td>
<input type= “checkbox” name= os value=”Windows1″> Windows
<input type= “checkbox” name= os value=”Linux1″> Linux
<input type= “checkbox” name= os value=”Mac1″> Mac
</td></tr>
</table><br>

<input type=”submit” value=”submit name”>
</form>
The output:

Follow

Get every new post delivered to your Inbox.