Basic form and data display using PHP

We will try to learn how a simple web form works and how to collect the data as entered by users. This is a very basic and common requirement so we have included all types of form component in our example. Before reading check this html form basic tutorial
For our tutorial we have used two files one is demo-basic-form.php file which has the html form and other file is demo-basic-form2.php file which has the script to collect the form data and display them.
Here is the code for demo-basic-form.php
<form method=post action='demo-basic-form2.php'>
<input type=hidden name=todo value=submit-form>
<table cellspacing=0 cellpadding=0 width='484' border=0 align=left bgcolor='#f1f1f1'>
<tr><td>Name</td><td><input type=text name=t1 value=''></td></tr>
<tr bgcolor='#ffffff'><td>Sex</td><td><input type=radio name=sex value='Male' >Male
|<input type=radio name=sex value='Female' >Female |</td></tr>
<tr><td>Languages you know</td><td><input type=checkbox name=c1 value=yes >PHP 
<input type=checkbox name=c2 value=yes >ASP &nbsp; 
<input type=checkbox name=c3 value=yes >JavaScript</td></tr>
<tr bgcolor='#ffffff'><td>Select one day</td><td><select name=s1>
<option value='' >Select One</option>

<option value=Mon >Mon</option>
<option value=Tue >Tue</option>
<option value=Wed >Wed</option>
<option value=Thu >Thu</option>
<option value=Fri >Fri</option>
<option value=Sat >Sat</option>
<option value=Sun >Sun</option>
</select> </td></tr>

<tr><td colspan=2><input type=submit value=Submit> </td></tr>
You can read the above code and remember each component has its own unique name which we can use to collect the data entered by user. Radio buttons of one group will have same name as one of them will be selected. You can read all form components in our html form section.
Here is the code for demo-basic-form2.php
<title>Demo of basic form design and submission to collect data by PHP</title>
<META NAME="DESCRIPTION" CONTENT="Basic form submission and data collection in PHP demo">
<META NAME="KEYWORDS" CONTENT="Basic form validation, demo of validation, form basic demo">


$name=$_POST['t1'];    // Name tag value
$todo=$_POST['todo']; // hidden tag value
$sex=$_POST['sex']; // Value of Sex, male or female
$c1=$_POST['c1']; // checkbox for PHP
$c2=$_POST['c2']; // checkbox of ASP
$c3=$_POST['c3']; // checkbox for JavaScript
$s1=$_POST['s1']; //  Drop down selection box for day

//// Let us display the variables /////

echo "<pre>
Name = $name
Todo = $todo
Sex = $sex
PHP = $c1
ASP = $c2
JavaScript = $c3
Day = $s1
Visitors Rating
Your Rating

Post Comment This is for short comments only. Use the forum for more discussions.

HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 All rights reserved worldwide Privacy Policy Disclaimer