PHP - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

PHP Form

PHP Form

shape Description

One of powerful PHP features is usage of HTML forms.The basic advantage of using PHP script is it automatically identifies the form element.

shape Example

[php] <!DOCTYPE html> <html> <body> <form action="abc.php" method="post"> Full Name: <input type="text" name="Name" /> E-mail: <input type="text" name="email" /> Phone: <input type="tel" name="phone" /> <input type="submit"/> </form> </body> </html> [/php] After submitting the form, the data will be transferred to abc.php and the data in the file abc.php can be accessed like below: [php] <!DOCTYPE html> <html> <body> Hello Welcome <?php echo $_POST["Name"]; ?>, Email ID is: <?php echo $_POST["email"]; ?> And phone Number is : <?php echo $_POST["phone"]; ?> </body> </html> [/php] Output: When clicked on Submit in the above output, the below output appears showing the details.

shape Alternative forms

The above process can also be done with PHP filter extension automatically. The variables $_POST['anyname'] and $_POST['anyage'] are sent automatically by PHP. Previously $_SERVER superglobal was used.Here superglobal $_POST is introduced that has entire POST data.Here,from method is POST. If GET method is used, then the information of form would have been stored in $_GET superglobal instead. Superglobal $_REQUEST can also be used, if source of request data is not taken into consideration. It possess the merged data of GET, POST and COOKIE.


shape Points

  • If the data is sent from a form using GET method then it will be visible to everyone.
  • If the data is sent from a form using POST method then it is hidden from others.