The most important step in keeping visitors bounded to website and acquiring there feedback is forms on Webpage. This module also gives a dynamic look to the web application. Processing a form is very much easy in PHP.
The main reason for this is every form element in HTML can easily be integrated with PHP script. The <form> tag has all elements needed to process a form specially the text area and buttons.
The complete logic in processing forms in PHP can be explained with simplification as, you request input from the user, store it in a variable and process it. Processing may be displaying input on another page or storing it in Database.
The reliability PHP has with storing form inputs in variables is, variables in PHP do not require explicit declaration of type, that is what kind of data is to be stored in it. You can store string, number, character or any other data type PHP supports.
There are two built in functions that help you to handle form inputs.
1. PHP $_GET
2. PHP $_POST
Let us explain you this module with the help of example.
The below is HTML code which asks user for inputs. Save the script as form.html.
<html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> From: <input type="text" name="from" /> You like to play: <input type="text" name="play" /> <input type="submit" /> </form> </body> </html>
Below is a PHP form script. This code takes the input from the above form using $_POST method. The below code has to be saved as welcome.php. The reason is you can see <form action=”welcome.php”> in the above html code. It invokes welcome.php when you click the submit button. Care has to be taken, save both the files on same directory.
<html> <body> <?php $name=$_POST["fname"]; $from=$_POST["from"]; $play=$_POST["play"]; echo "Your name is:\t".$name."<br>"; echo "Your are from:\t".$from."<br>"; echo "You play:\t".$play."<br>"; ?> <br> Thank you </body> </html>
Here is the easy execution shots for you:
This is what after you click the submit button
If you need any further assistance do write to us in comments. We would be glad to reply.
- 10 Best Online Photo Sharing Websites
- Best Video Players for Android devices in 2019
- Best Loan apps for Android
- Best Photo Editing Apps for Android
- Best Video Editor Apps for iPhone
- Best Video Editing Apps for Android
- Best Android Launchers
- Best Android Apps To Draw On Pictures
- Best Android Keyboards with Clipboard Features
- Best Poster Maker Apps for Android