Php Practical 11
Php Practical 11
3. How does the form information get from the browser to the server?
When a user fills out a form and clicks the "submit" button, the form information is sent
from the browser to the server using the HTTP POST method.The browser collects all
the form input values and organizes them into key-value pairs, where the keys are the
names of the form elements and the values are the data entered by the user.The browser
then creates an HTTP request containing this data and sends it to the server. The request
includes a header and a body, where the body contains the form data. The header
includes the method used (POST), the URL of the server script that will process the data,
and other information about the request.On the server side, the script specified in the
form's "action" attribute receives the request and extracts the form data from the body of
the request. In PHP, the form data is stored in the $_POST superglobal array.The server-
side script can then process the form data, validate it, and perform any necessary actions
based on the input. It can also generate a response to send back to the browser, which can
be in the form of HTML, JSON, or other formats. The response is then sent back to the
browser using the HTTP response protocol.
Exercise Related Question
1. Write a PHP program that demonstrate form elements List Box, Combo Box.
<!DOCTYPE html>
<html>
<head>
<title>List Box and Combo Box Example</title>
</head>
<body>
<?php
// Define options for list box
$options = array("Red", "Green", "Blue", "Yellow");
<?php
// If form submitted, display selection
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$color = $_POST["color"];
echo "<p>You selected: $color</p>";
}
?>
<?php
// If form submitted, display selection
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$country = $_POST["country"];
if ($country != "") {
echo "<p>You selected: $country</p>";
}
}
?>
</body>
</html>
2. Demonstrates Hidden Fields
<form action="page2.php" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<input type="submit" value="Submit">
</form>