Variable Fails To Be Set
Posted: Thu Aug 14, 2008 7:35 pm
I recently decided to clean my page up with making an include file for functions. The problem is, I run a field checking script, that will see if someone filled out a field. I have tried it using the filter_has_var method and the isset method (since on the PHP site it said that they were the same thing) for checking if there was something in the fields. In any case, whenever I have it check all the fields, $fail goes funky and a lot of my code doesn't work right. If I take out 1 !, then all the fields work but that one. I'm figuring this is a syntax issue, but I can't find the problem (for a few days now). Here's the files:
orderform1.php
functions.php
I believe the problem may be in function ordercheck(). That is the area that can make things go funky. Thanks for the help, I appreciate it!
orderform1.php
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include('functions.php');
if ( $_POST ){
ordercheck();
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Title</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="shortcut icon" href="favicon.gif" type="image/vnd.microsoft.icon" />
<link rel="icon" href="favicon.gif" type="image/vnd.microsoft.icon" />
</head>
<body>
<div id="ocontainer">
<h1>
<center>
CD Order Form
</center>
</h1>
<hr />
<?php
if ( $_POST ){
if( $fail == true ){
echo "<div id=\"error\" >";
ordererror();
echo "</div><hr />";
}
}
?>
<div id="picture">
<h2> You are ordering:<br />
<br />
Audio Eye Candy<br />
<br />
<img src="aec.gif" /><br />
</h2>
</div>
<div id="content3">
<h3>
<?php
if( !$_POST || $fail == true ){
printform();
}
?>
<?php
if ( isset( $fail ) && $fail == false ){
echo "Please verify this information is correct.<br /><br />";
echo "Name: ".$_POST["fname"]." ".$_POST["lname"]."<br />";
echo "Email: <a href=\"mailto:".$_POST['email']."\">".$_POST['email']."</a><br />";
echo "Address: ".$_POST["address"]."<br />";
echo "City: ".$_POST["city"]."<br />";
echo "State: ".$_POST["state"]."<br />";
echo "Zip Code: ".$_POST["zip"]."<br />";
echo "CD's: ".$_POST["cd"]."<br />";
echo "Total: $".$total."<br />";
echo "Shipping: ".$_POST["shipping"]."<br />";
echo "How did you find out about our CD: ".$_POST["found"]."<br />";
echo "Comments: ".$_POST["comments"]."<br />";
}
?>
</h3>
</div>
</div>
</body>
</html>Code: Select all
<?php
/*
This code includes functions for displaying and checking an order form.
functions:
-ordercheck()
-ordererror()
-form()
*/
function ordercheck(){
global $fail;
$fail = false;
if( !isset( $_POST["fname"] ) ){
$_POST["fname"]="";
$fail=true;
}
if( !isset( $_POST["lname"] ) ){
$_POST["lname"]="";
$fail=true;
}
if( !isset( $_POST["email"] ) ){
$_POST["email"]="";
$fail=true;
}
if( !isset( $_POST["email"] ) ){
if( !filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL ) ){
$_POST["email"]="";
$fail=true;
}
}
if( !isset( $_POST["phonenumbera"] ) ){
$_POST["phonenumbera"]="";
$fail=true;
}
if( !isset( $_POST["phonenumberb"] ) ){
$_POST["phonenumberb"]="";
$fail=true;
}
if( !isset( $_POST["phonenumberc"] ) ){
$_POST["phonenumberc"]="";
$fail=true;
}
if( !isset( $_POST["address"] ) ){
$_POST["address"]="";
$fail=true;
}
if( !isset( $_POST["city"] ) ){
$_POST["city"]="";
$fail=true;
}
if( !isset( $_POST["zip"] ) ){
$_POST["zip"]="";
$fail=true;
}
if( !isset( $_POST["cd"] ) ){
$_POST["cd"]="";
$fail=true;
}
if( $fail == false ){
if( !isset ($_POST["shipping"] ) ){
$_POST["shipping"] = "No";
}
}
}
function ordererror(){
if( $_POST["fname"] == "" ){
echo "*Please enter your first name.<br />";
}
if( $_POST["lname"] == "" ){
echo "*Please enter your last name.<br />";
}
if( $_POST["email"] == "" ){
echo "*Please enter a valid email address.<br />";
}
if( $_POST["phonenumbera"] == "" || $_POST["phonenumberb"] == "" || $_POST["phonenumberc"] == "" ){
echo "*Please enter your phone number.<br />";
}
if( $_POST["address"] == "" ){
echo "*Please enter your address.<br />";
}
if( $_POST["city"] == "" ){
echo "*Please enter your city.<br />";
}
if($_POST["state"]== "--State--") {
echo "*Please select your state.<br />";
}
if( $_POST["zip"] == "" ){
echo "*Please enter your zip code.<br />";
}
if( $_POST["cd"] == "" ){
echo "*Please enter the number of CD's you are buying.<br />";
}
}
function printform(){
/*--CODE FOR A FORM HERE--(let me know if you want to see the form It displays content based on if the user has already input valid responses. Like it will set the input from last time and code it as the value="input" from the last accept.)*/
}