PHP Form
In this post I would create a simple form in HTML (with just two input boxes) and then write PHP code to retrieve the form values a user submit using PHP.
So in our sample project there are only two files:
- form.html
- form-handler.php
Let see the form.html code:
PHP Form
This form will generate following output:
There are following points to note:
- The action attribute value is form-handler.php. It shows, when the form is submitted form-handler.php would process the form. Processing includes, retrieving form data and storing it somewhere if you want to.
- The input text boxes names are first-name and last-name. On PHP page, we would use these names to retrieve the values user entered in the PHP form.
The Server Side
The form-handler.php code retrieves the both input values and display on the next page. Lets first look at the form-handler.php code.
Please note following points regarding we process the form values at server side:
$first_name = $_REQUEST['first-name'];
$last_name = $_REQUEST['last-name']; ?>
echo "
Form Handler
First Name : $first_name
Last Name: $last_name
";
- The PHP receives the submitted values and put them into global associatve array $_REQUEST. We can retrieve values using the input text field names.
- In the code above, we have retrieved the values from $_REQUEST array, store them into our local variable and then printed those values inside the HTML BODY element.
When we submit the form, following output is displayed:
Respected Sir finally I found you. Kindly share how to make Rest API in php and way to use it in my (final year project) ie: Android Application
ReplyDelete