Skip to main content
PHP Form
Prepared By:-
Kale J. N.
Assistant Professor,
Computer Engineering,
Sanjivani College of Engineering, Kopargaon
Prepared By: Kale J. N.
action attribute:-
The action attribute specifies where the form data will be sent after
the user clicks the submit button. It tells the browser which page or
script will process the form data
Prepared By: Kale J. N.
<form action="welcome.php"
method="post">
Name:
<input type="text" name="name">
<input type="submit">
</form>
• //When the user clicks Submit:
• //The form data goes to welcome.php
•
• If action="" then Then the form
submits to the same page.
Prepared By: Kale J. N.
Method attribute
• The method attribute specifies
how the form data will be sent
to the server.
• There are two main methods:
• GET
• POST
Prepared By: Kale J. N.
GET Method
<form action="welcome.php"
method="get">
Name:
<input type="text"
name="name">
<input type="submit">
</form>
//After submission, URL becomes:
//welcome.php?name=sai
• In GET method, form data is
sent through the URL.
• Characteristics of GET
• Data is visible in URL
• Limited data size
• Less secure
Prepared By: Kale J. N.
POST Method
<form action="welcome.php"
method="post">
Name:
<input type="text"
name="name">
<input type="submit">
</form>
//URL will look like:
//welcome.php
• In POST method, form data is
sent inside the HTTP request
body, not visible in URL.
• Data is hidden.
Prepared By: Kale J. N.
Difference Between GET and POST
Feature GET POST
Data visibility Visible in URL Hidden
Security Less secure More secure
Data size Limited Large
Usage Search forms Login, registration
Prepared By: Kale J. N.
Superglobals
• PHP provides 9 superglobal
variables:
• $GLOBALS
• $_SERVER
• $_REQUEST
• $_POST
• $_GET
• $_FILES
• $_ENV
• $_COOKIE
• $_SESSION
Prepared By: Kale J. N.
• Superglobals are built-in PHP
variables that are available in all
scopes of a PHP script.
• This means:
• They can be accessed anywhere in
the program
$_GET Superglobal
• Definition
• $_GET is used to collect form
data sent using the GET
method.
• The data is visible in the URL.
<?php
$name = $_GET['name'];
echo "Hello " . $name;
?>
Prepared By: Kale J. N.
$_POST Superglobal
• Definition
• $_POST is used to collect form
data sent using POST method.
• The data is not visible in the
URL.
<?php
$name = $_POST['name'];
echo "Hello " . $name;
?>
Prepared By: Kale J. N.
Retrieving Data (Radio Button)
<input type="radio"
name="gender" value="Male">
Male
<input type="radio"
name="gender" value="Female">
Female
$gender = $_POST['gender'];
Prepared By: Kale J. N.
Retrieving Data (Check box)
<input type="checkbox"
name="hobby[]"
value="Reading"> Reading
<input type="checkbox"
name="hobby[]" value="Music">
Music
$hobby = $_POST['hobby'];
foreach($hobby as $h)
{
echo $h;
}
Prepared By: Kale J. N.
Retrieving Data (Drop down List)
<select name="city">
<option
value="Nashik">Nashik</option>
<option
value="Pune">Pune</option>
</select>
$hobby = $_POST['hobby'];
foreach($hobby as $h)
{
echo $h;
}
Prepared By: Kale J. N.
$city = $_POST['city'];
Prepared By: Kale J. N.