I am trying to teach myself PHP, im trying to generate a form that validates in php Im having issues with my checkbox value calculations I know i should construct a function Im trying to make it so if the user clicks the mealplan box the appropriate price gets added to the convention cost.
<!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
// define the variables
$fName = $_POST["fName"];
$lName = $_POST ["lName"];
$city = $_POST ["city"];
$state = $_POST ["state"];
$zipCode = $_POST["zipCode"];
$other = $_POST ["other"];
$chkOne = $_POST["chkOne"];
$chkTwo = $_POST["chkTwo"];
$chkThree = $_POST["chkThree"];
$mealPlan = $_POST[""];
//1 to 1000
//generate conf id number
$confId = rand(1,1000);
$no_errors = TRUE;
$total = 0;
//begin form filter
if(!isset($_POST['mealPlan']) &&
$_POST['mealPlan'] == 'Yes')
{ $mealPlan== 'Yes';
$no_errors = FALSE;
}
checkInput();
calcPrice();
printConf();
//checkInput
function checkInput() {
if (filter_has_var(INPUT_POST, "chkOne")){
print "<p>ONE DAY CONFERENCE</p> \n";
$total += filter_input(INPUT_POST, "chkOne");
}
if (filter_has_var(INPUT_POST, "chkTwo")){
print "<p>TWO DAY CONFERENCE</p> \n";
$total += filter_input(INPUT_POST, "chkTwo");
}
if (filter_has_var(INPUT_POST, "chkThree")){
print "<p>THREE DAY CONFERENCE</p> \n";
$total += filter_input(INPUT_POST, "chkThree");
}
//end $total
if (filter_has_var(INPUT_POST, "mealPlan")){
}
if (filter_has_var(INPUT_POST, "noFood")){
}
// do they want the meal plan
$track = filter_input(INPUT_POST, "track");
// what conference track are they on
if(empty($fName))
{
$no_errors = FALSE;
echo '***FIRST NAME FIELD REQUIRED***** <br />' ;
}
//get users first name
if(empty($lName))
{
$no_errors = FALSE;
echo '****LAST NAME FIELD REQUIRED***** <br /> ';
}
// get users last name
if(empty($city))
{
$no_errors = FALSE;
echo '****CITY FIELD REQUIRED***** <br /> ';
}
//get user city
if(empty($state))
{
$no_errors = FALSE;
echo '***STATE NAME FIELD REQUIRED***** <br /> ';
}
//get user state
if(empty($zipCode))
{
$no_errors = FALSE;
echo '****ZIPCODE FIELD REQUIRED***** <br /> ';
}
//get user zip code
if(empty($other))
{
$no_errors = FALSE;
echo '****TEXT FIELD REQUIRED***** <br /> ';
}
//get user additional comments
if ($no_errors == FALSE) {
echo "<br> <a href='major1progress.html'>Go back to form</a>";
}
}//end function checkInput
//beging function calculateCost
function calcPrice(){
$confTotal =filter_input(INPUT_POST,"confTotal");
$total = filter_input (INPUT_POST, "total");
$mealPlan = filter_input (INPUT_POST, "mealPlan");
IF (! filter_has_var (INPUT_POST, "mealPlan" )){
$total =="100" ; $confTotal = $total+= 50;
}
else if ($total=="175"){ $confTotal = $total +=75;
}
else if ($total =="225"){$confTotal = $total +=100;
$no_errors == TRUE;
}}
//end function cacluclateCost
//begin function printConf
function printConf(){
$no_errors = FALSE;
if ($no_errors == TRUE) {
print " <p> $fName $lName, <br />you have registered for Nerd Roundup 2013<br />
your planned track is $track<br />
The total cost is: \$$total <br />
<br /> Please make sure to bring cash, or your credit card to
pay for the conference on the first day<br />
Your additional comments are as follows:
$other <br /> </p>
<p>Your Nerd Roundup confirmation number is $confId .</p> <br /> \n";
}
}
//end function printConf
?>
</body>
</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">
<style>
body
{
color:black;
font-size:20px;
}
h1
{
color:orange;
text-align:center;
font-size:30px;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
</style>
<title>MAJOR PROJECT 1 PHP </title>
</head>
<body>
<h1>Nerd Roundup </h1>
<form method = "POST"
action = "http://localhost/Assignments php class/threeprogress.php">
<fieldset>
<label>
Please type your first name:
</label>
<input type = "text"
name = "fName"
value = "" /> <br />
<label>
Please type your Last name:
</label>
<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 />
<label for="other">Anything else you want to add?</label>
<textarea id="other" name="other">