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.
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
<html>
<head>
<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">
</head>
<body>
<?Php
$name=$_POST['t1']; // Name tag value
$todo=$_POST['todo']; // hidden tag value
$gender=$_POST['gender']; // Value of gender, 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
gender = $gender
PHP = $c1
ASP = $c2
JavaScript = $c3
Day = $s1
</pre>";
?>
</body>
</html>