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
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 ">
<META NAME="KEYWORDS" CONTENT="Basic form validation, 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
$s1=$_POST['s1']; // Drop down selection box for day
//// Let us display the variables /////
Name = $name
Todo = $todo
Sex = $sex
PHP = $c1
ASP = $c2
Day = $s1