Saturday, June 15, 2013
Simple form validation
This would be the php file
die.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body
{
background-color:#FF00FF;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
h1 {text-align:center;
}
</style>
<title>Assignment3</title>
</head>
<body>
<h1>Personal Information </h1>
<?php
if (!$_POST['fName'] )
{
die('You did not complete The Name field, please go back');
}
if (!$_POST['lName'] )
{
die('You did not complete all of the Last Name fields please go back');
}
if (!$_POST['state'] )
{
die('You did not complete all of the state fields please go back');
}
if (!$_POST['city'] )
{
die('You did not complete all of the city please go back');
}
if (!$_POST['zipCode'] )
{
die('You did not complete all of the zipcodefields please go back');
}
$fName = filter_input(INPUT_POST, "fName");
$lName = filter_input(INPUT_POST, "lName");
$city = filter_input(INPUT_POST, "city");
$state = filter_input(INPUT_POST, "state");
$zipCode = filter_input(INPUT_POST, "zipCode");
echo <<<HERE
<h3> Hi there, $fName $lName, <br /> so you live in $city,<br /> in the great state of $state.<br /> I hear the climate around $zipCode is great this time of year.
<br /> $fName, I hear that $state has alot to offer as far as recreation goes.<br />I hope that you have a great summer in $city. <br /></h3>
HERE;
?>
</body>
</html>
AND THIS THE VALIDATE.HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body
{
background-color:#d0e4fe;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
</style>
<title>Validate-Assignment 3</title>
</head>
<body>
<h1>ASSIGNMENT 3
PHP FORM VALIDATION</h1>
<h3>Please put information into the fields.</h3>
<form method = "POST"
action = "http://localhost/Assignments php class/die.php">
<fieldset>
<label>
Please type your first name:
</label>
<input type = "text"
name = "fName"
value = "" /> <br />
Please type your last name:
<input type = "text"
name = "lName"
value = "" /> <br />
Please type your city:
<input type = "text"
name = "city"
value = "" /> <br />
Please type your State:
<input type = "text"
name = "state"
value = "" /> <br />
Please type your Zipcode:
<input type = "text"
name = "zipCode"
value = "" /> <br />
<input type = "submit" />
</fieldset>
</form>
</body>
</html>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment