WEB FORMS
HTML WITH PHP
•TEXT BOX
•TEXT AREA
•LIST BOX
•CHECK BOX
•RADIO BOX
•HIDDEN FIELDS
GET Argument
The GET method passes arguments from one page to the
next as part of the Uniform Resource Locator query
string.
GET appends the indicated variable names and values to
the URL designated in the ACTION attribute with a
question-mark separator and submits the whole thing to
the processing agent
ADVANTAGES
It constructs the actual new and differentiable URL query
strings.
User can book-mark this page. The result of forms using
the POST method are not bookmarkable.
GET Argument
Disadvantage
•The GET method is not suitable for logins because the
user name and password are fully visible on screen as
well as potentially stored in the client browsers memory
as at visited page.
•Every GET submission is recorded in the web server log,
data set included.
•GET method assigns data to a server environment
variable, the length of URL is limited.
Use of GET Argument
Radio.html
Radio.php
Use of GET Argument
<html> <input name="Question1"
type="radio" value="Delhi">
<head><title></title></head>
Delhi
<body>
<br>
<form method=“GET”
action="radio.php"> <input name="Question1"
type="radio" value="Kolkata">
What is the capital of INDIA?
Kolkata
<br>
<br>
<br>
<br>
<input name="Question1"
<input type="submit"
type="radio“
value="submit">
value="Mumbai">
</form>
Mumbai
</body>
<br> CONT .. Radio.html
</html>
Use of GET Argument
<html>
<head><title></title></head>
<body>
<?php
echo "You selected the answer: $_GET[Question1]";
?>
</body>
</html>
Radio.php
POST arguments
POST is the preferred method of form submission today,
particularly in non- indempotent uses, such as adding
information to a database.
No visible change to the URL will results according to the
different data submission.
Advantages
It is more secure than get because user entered information
is never visible in the URL query string, in the server log or
on screen.
There is a much larger limit on the amount of data that can
be passed (a couple of K/bites rather than a couple of
hundred characters.
POST arguments
Disadvantages
The result at a given movement cannot be book-marked.
This method can be incompatible with certain firewall setups,
which strip the form data as a security measures.
$_POST
•$_POST is a superglobal array.
•This array is available to a script at anytime no matter what the
scope.
•Anything submitted via the POST method is available in the
$_POST array.
•Index of the $_POST array is the name we gave to the HTML
form element.
•A form element being a button, textbox, checkbox, etc, that is
what the index of the $_POST array will be in order to access the
data from that element.
•The $_POST array is only available in PHP versions 4.1.0 and later.
•In earlier version, you will need to use the $HTTP_POST_VARS array.
•The $HTTP_POST_VARS array works the same as the $_POST array, except it is
not a
•superglobal. That is, it is not available in all scopes. In fact, if register_globals is
turned
Use of Text Box
Text.html
Text.php
Text.html
<html>
<head><title></title></head>
<body>
<form method="POST" action="text.php">
What is your favorite web site?
<input name="WebSites" type="text">
<br>
<input type="submit“ value="submit">
</form>
</body>
</html>
Text.php
<html>
<head><title></title></head>
<body>
Your favorite web site is:
<?php
echo $_POST['WebSites'];
?>
</body>
</html>
Use of TextArea
Textarea.html
Textarea.php
Textarea.html
<html>
<head><title></title></head>
<body>
<form method="POST"
action="textarea.php">
What are your favorite web sites?
<textarea name="WebSites" </textarea>
cols="50" rows="5"> <br>
http:// <br>
http://
<br>
<input type="submit" value="submit">
http:// </form>
http:// </body>
</html>
Textarea.php
<html>
<head><title></title></head>
<body>
Your favorite web sites are:
<?php
echo $_POST['WebSites'];
?>
</body>
</html>
Use of CHECKBOXES
checkboxes.html
checkboxes.php
checkboxes.html
<html>
<head><title></title></head>
<body>
<form method="POST" action="checkboxes.php">
Have you ever eaten Egg before?
<input name="Choice1" type="checkbox" value="Egg">
<br>
Have you ever eaten Apple before?
<input name="Choice2" type="checkbox"
value="Apple">
<br>
checkboxes.html
Have you ever eaten Grapes before?
<input name="Choice3" type="checkbox"
value="Grapes">
<br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>
checkboxes.php
<html>
<head><title></title></head>
<body>
Your Selected Check boxes are For :
<br>
<?php
echo "$_POST[Choice1]<br>";
echo "$_POST[Choice2]<br>";
echo "$_POST[Choice3]<br>";
?>
</body>
</html>
Use of RADIO Button
Radio.html
Radio.php
Use of Radio Button
<html>
<input name="Question1"
<head><title></title></head> type="radio" value="Delhi">
<body> Delhi
<form method=“GET” <br>
action="radio.php">
<input name="Question1"
What is the capital of INDIA? type="radio" value="Kolkata">
<br> Kolkata
<br> <br>
<input name="Question1" <br>
type="radio“
<input type="submit"
value="Mumbai"> value="submit">
Mumbai </form>
<br> CONT .. </body>
</html> Radio.html
Radio.php
<html>
<head><title></title></head>
<body>
<?php
echo "You selected the answer: $_GET[Question1]";
?>
</body>
</html>
Use of LIST BOX
listbox.html
listbox.php
listbox.html
<html>
<head><title></title></head>
<body>
<form method="POST" action="listbox.php">
What price of car are you looking to buy?
<br>
<br>
<select name="Price">
<option>Under Rs.2,00,000</option>
<option>Rs.2,00,000 - Rs.3,00,000</option>
<option>Rs.3,00,000 - Rs.5,00,000</option>
<option>Over Rs.5,00,000</option>
</select>
<br>
listbox.html Cont….
What size of engine would you consider?
<br>
<select name="EngineSize[]" multiple>
<option>1.0L</option>
<option>1.4L</option>
<option>1.6L</option>
<option>2.0L</option>
</select>
<br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>
listbox.php
$Choice0 =
<html> $_POST['EngineSize'][0];
$Choice1 =
<head><title></ $_POST['EngineSize'][1];
title></head> $Choice2 =
<body> $_POST['EngineSize'][2];
$Choice3 =
Your Selected $_POST['EngineSize'][3];
options for Car are : echo "<br>Engine Size(s):
$Choice0";
<br>
echo "$Choice1";
<?php echo "$Choice2";
echo "Price Range: echo "$Choice3";
$_POST[Price]"; ?>
</body>
</html>
Use of
Hidden
fields
hidden.php
Hidden2.php
hidden.php
<html>
<head></head>
<body>
<?php
$Message1=“Sanjay Agrawal";
$Message2=“Ravi Kapoor";
$Message3=“M.A. Rizvi";
echo "<form method='GET' action='hidden2.php'>";
echo "Which of the following would win in a shootout?";
echo "<select name='ListBox'>";
echo "<option>$Message1</option>";
echo "<option>$Message2</option>";
hidden.php
echo "<option>$Message3</option>";
echo "</select><br><br>";
echo "<input type='hidden' name='Hidden1' value='$Message1'>";
echo "<input type='hidden' name='Hidden2' value='$Message2'>";
echo "<input type='hidden' name='Hidden3' value='$Message3'>";
echo "<input type='submit' value='Submit'>";
echo "</form>";
?>
</body>
</html>
hidden2.php
<html>
<head><title></title></head>
<body>
<?php
echo "The three options were:<br>";
echo "$_GET[Hidden1]<br>";
echo "$_GET[Hidden2]<br>";
echo "$_GET[Hidden3]<br>";
echo "<br>You selected:<br>";
echo "$_GET[ListBox]";
?>
</body>
</html>
loan.html
loan.html
<html>
<head><title></title></head>
<body>
<b>XYZ Credit Bank Loan Application Form</b>
<form method="POST" action="loan.php">
First Name:
<input name="FirstName" type="text">
Last Name:
<input name="LastName" type="text">
Age:
<input name="Age" type="text" size="3">
<br>
<br>
Address:
<textarea name="Address" rows=“4” cols=“40”>
Cont…
loan.html Cont… 2
<br>
<br>
What is your current salary?
<select name="Salary">
<option value=200000>Under Rs. 2,00,000</option>
<option value=250000>Rs. 2,00,00 to Rs.
3,00,000</option>
<option value=350000>Rs. 3,00,000 to Rs.
4,00,000</option>
<option value=500000>Over Rs. 5,00,000 </option>
</select>
<br>
<br>
Cont…
loan.html Cont…. 3
How much do you want to borrow?<br><br>
<input name="Loan" type="radio" value='100000'>Our Rs.
2,00,000 package at 8.0% interest
<br>
<input name="Loan" type="radio" value='500000'>Our Rs.
3,00,000 package at 11.5% interest
<br>
<input name="Loan" type="radio" value='1000000'>Our Rs.
5,00,000 package at 15.0% interest
<br>
<br>
<input type="submit" value="Click here to Submit application">
<input type="reset" value="Reset application form">
</form>
</body>
</html>
loan.php
<html>
<head><title></title></head>
<body>
<b>XYZ Credit Bank Loan Application Form</b>
<br>
<br>
<?php
$SalaryAllowance = $_POST['Salary']/2;
$AgeAllowance = 100/$_POST['Age‘];
$LoanAllowance = $SalaryAllowance * $AgeAllowance;
echo "Loan wanted:$_POST[Loan]<br>";
loan.php
echo "Loan amount we will allow:
$LoanAllowance<br><br>";
if ($_POST['Loan'] <= $LoanAllowance) echo "Yes,
$_POST[FirstName] $_POST[LastName], we are delighted
to accept your application";
if ($_POST['Loan'] > $LoanAllowance) echo "Sorry,
$_POST[FirstName] $_POST[LastName], we cannot accept
your application at this time";
?>
</body>
</html>
Formatting of Numbers
• we can format the number with specifying
whether to display the digits with decimal or
without decimal or number of digits to display
after the decimal or to round off.
• We can place comma ( ,) after a group of
thousands.
• We can use other symbols in place of comma (,)
for thousands and we also can replace (.) dot with
symbol of our choice to be used as decimal.
• Using PHP number_format function we can do all
these formatting.
Formatting of Numbers
Examples:
$number=2512589.66785;
echo "Number = $number ";
echo " No. after formatting =
".number_format($number);
The above line will display 2,512,590
( without decimal and rounded)
echo "<br> The value after formating =
".number_format($number,3);
This Will display 2,512,589.668 ( with comma
symbol after each thousand and 3 digits after
decimal rounded )
Formatting of Numbers
echo "<br> The value after formating =
".number_format($number,3,"#",":");
This Will display 2:512:589#668 ( with : after
each thousand and # as decimal symbol )