How to use forms in PHP

PHP forms Lesson 9 Tutorials PHP

9. Forms and form processing

9. Forms and form processing

Accessing inputs from HTML forms in PHP is used to interact with users. The form is written in standard HTML selecting the form open and closing tags then creating an input field.

As you may already know in HTML there are different ways to submit a form. There are two methods used one is the GET and the other is POST. GET method will show the field list and values in the address bar, as POST does not append data in the address bar. If data is sensitive you should be using POST if not you can use GET.

Submitting a form is done to the ACTION value, in the HTML form. TO initiate the form submission you can use a Submit button.

Once the form is submitted to a PHP file you can get the field value using $_POST['name']; or $_GET['name'] using the value name to correspond to the form field name value in your HTML form.

PHP Code example


<form name ="myForm" Method ="POST" Action ="">
<input type="text" name ="name" value="<?PHP echo $name;?>">
<input type="submit" />


$name = $_POST['name'];
echo $name;

The above example will display out the name that was entered into the form field.

For more advanced options if you have the PHP code on the same page as your form you can automatically fill out the field value using the PHP variable. value="<?PHP echo $name;?>"

Do Not Sell My Personal Information