0% found this document useful (0 votes)
56 views

Php Practical 11

The document outlines a laboratory experiment for a Mobile Application Development course, focusing on designing web pages using form controls such as List Box, Combo Box, and Hidden Fields. It includes practical questions about PHP superglobals, handling forms with multiple selections, and the process of sending form data from the browser to the server. Additionally, it provides example PHP code demonstrating the implementation of List Box, Combo Box, and Hidden Fields in web forms.

Uploaded by

aafu202
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Php Practical 11

The document outlines a laboratory experiment for a Mobile Application Development course, focusing on designing web pages using form controls such as List Box, Combo Box, and Hidden Fields. It includes practical questions about PHP superglobals, handling forms with multiple selections, and the process of sending form data from the browser to the server. Additionally, it provides example PHP code demonstrating the implementation of List Box, Combo Box, and Hidden Fields in web forms.

Uploaded by

aafu202
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF COMPUTER ENGINEERING

Subject: Mobile Application Development Subject Code: 22619


Semester: 6 Course: CO6I-A
Laboratory No: Name of Subject Teacher:
Name of Student: AFIF IRFAN NAZIR Roll Id: 21203A1005
Experiment No: 11
Title of Experiment Design web page using following form controls. a) List Box b) Combo
box c) Hidden field

 Practical Related Question


1. Explain the superglobals in PHP?
Superglobals in PHP are special variables that are available in all scopes and can be
accessed from anywhere within a PHP script. They are prefixed with a double underscore
(__) and are denoted with a global scope.Superglobals can be accessed from anywhere in
the PHP script, and their values can be modified like any other variable. However, it is
important to sanitize and validate user input before using it in any superglobal variable.

2. How does PHP handle forms with multiple selections?


PHP handles forms with multiple selections using arrays. When a form has multiple
selections (such as checkboxes or dropdowns with multiple selections enabled), the name
attribute of the form element must be specified as an array.

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");

// Define options for combo box


$countries = array("USA", "Canada", "Mexico", "Japan", "China");
?>

<h2>List Box Example</h2>


<form method="post">
<select name="color">
<?php
// Loop through options and create list box
foreach ($options as $option) {
echo "<option value=\"$option\">$option</option>";
}
?>
</select>
<input type="submit" value="Submit">
</form>

<?php
// If form submitted, display selection
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$color = $_POST["color"];
echo "<p>You selected: $color</p>";
}
?>

<h2>Combo Box Example</h2>


<form method="post">
<select name="country">
<option value="">Select a country</option>
<?php
// Loop through options and create combo box
foreach ($countries as $country) {
echo "<option value=\"$country\">$country</option>";
}
?>
</select>
<input type="submit" value="Submit">
</form>

<?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>

<form action="page2.php" method="post">


<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<input type="hidden" name="page" value="page1">
<input type="submit" value="Submit">
</form>
<?php
if(isset($_POST['name']) && isset($_POST['page'])) {
$name = $_POST['name'];
$page = $_POST['page'];
echo "Hello $name! You came from $page.";
}
?>

You might also like