FORM HANDLING IN PHP
FORM HANDLING AND GET AND POST METHOD IN PHP (PART-1)
FORM HANDLING AND GET AND POST METHOD IN PHP (PART-2)

In This Blog, you will learn how to access the form in PHP by using get and post methods. Form handling is the most important concept of PHP programming language.

What Is Form ?

  • It is a Web page containing fields
  • It is used by users to enter information
  • It passes entered data from a client to a server

Form

  • Steps for handling HTML forms and process information are as follows:
    • User enters information in an HTML form and sends it to the Web server
  • Web server passes the information to the PHP script engine for:
    • Processing the information
    • Sending output back to the Web browser

Introduction To Form Handling

  • Form data is passed to the Web server using following methods:
    • GET
    • POST

Working Of Web server

  • Accepts the information
  • Processes the application data
  • Stores it to the database

HTML <FORM> Tag

  • HTML <Form> tag is:
    • Used to create HTML form
    • Included within the <Form> and </Form> tag
  • Attributes of an HTML form tag are:
    • Action – defines URI where the form data is sent after it has been submitted
    • Method – defines protocols that are used to submit the form data set
  • Method protocols are of two types:
    • GET
    • POST

Using the GET Method

  • Directs the Web browser to send the encoded user information to the processing agent
  • Appends the encoded information at the end of the URL by a question mark (?) which separates URL and form information
  • The form data sent in the URL is a stream of name/value pair separated by ampersand (&)
  • The query string is appended with the following URL:
    • http://www.information.com/text.php?Name=john&age=18
  • The restrictions of GET method are as follows:
    • Form data set values are restricted to American Standard Code for Information Interchange (ASCII) characters
    • Amount of information transferred is limited
    • Length of the query string is restricted to 255 characters

Using the POST Method

  • Directs the Web browser to send all the user information to the processing agent
  • Uses message body of an HTTP request to send the information
  • Has capacity to transmit more information as:
    • No physical limit on the amount of information passed in the HTTP request message body
  • Uses variables to pass form information
  • The drawback of POST method is as follows:
    • Information sent is not encrypted, so hackers can easily access it

Source Code

Page1.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
    
    <form action="page2.php" method="get">
    
        <input type="text" placeholder="Enter Name" name="s_name">
        <br><br>
        <input type="number" placeholder="Enter Age" name="s_age">
        <br><br>
        <label>Select Gender: </label>
        <input type="radio" name="gender" value="Male">
        <label> Male</label>
        <input type="radio" name="gender" value="Female">
        <label> Female</label>  
        <br><br>
        <input type="email" placeholder="Enter Email" name="s_email">
        <br><br>
        <input type="submit" value="Submit" name="SubmitBtn">
        
    </form>
    
    
</body>
</html>

<!--query string-->
<?php
//
//if(isset($_POST['SubmitBtn']))
//{
//$name = $_POST['s_name'];
//$age = $_POST['s_age'];
//$gender = $_POST['gender'];
//$email = $_POST['s_email'];
//
//echo "Your Name Is: " . $name . "<br>";
//echo "Your Age Is: " . $age . "<br>";
//echo "Your Gender Is: " . $gender . "<br>";
//echo "Your Email Is: " . $email . "<br>";
//}

?>

Page2.php Code

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
    
    <?php

if(isset($_GET['SubmitBtn']))
{
$name = $_GET['s_name'];
$age = $_GET['s_age'];
$gender = $_GET['gender'];
$email = $_GET['s_email'];

echo "Your Name Is: " . $name . "<br>";
echo "Your Age Is: " . $age . "<br>";
echo "Your Gender Is: " . $gender . "<br>";
echo "Your Email Is: " . $email . "<br>";
}

?>

    
</body>
</html>

Download Notes Of This Blog From the link given below

https://www.mediafire.com/file/1wo1zeeq93l6bhx/FORM+HANDLING+IN+PHP.pptx/file

Download Source Code of This Blog From the link given below

https://www.mediafire.com/file/zurivrrkxtftgto/Forms.rar/file

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *