Hi,
Can someone please tell me what I am doing wrong in the PHP code. I coded an html form to run within the php page and have that page self process itself. I need the php to echo out via the two functions when the user hits submit. I have that working but my form verification function "handleform()" keeps on saying that the form is not valid even when the user fills in all of the required fields. Any help you can offer me is greatly appreciated.
Thanks,
Klevy09
<HTML>
<HEAD>
<TITLE>tates old fashioned ice cream - cakes</TITLE>
<LINK REL="STYLESHEET" HREF="http://www.tatesicecream.com/tates_style.css" TYPE="TEXT/CSS">
</HEAD>
<BODY>
<?
function email_order()
{
global $firstname, $lastname, $email, $phone, $address, $address2, $city, $state, $zip, $cake_needed_by, $cake_size, $cake_flavor, $requests;
$body = ("<H3>You have a new Ice Cream Cake Order!</H3>Please call the customer at the number below to confirm this order. Upon order confirmation, bill the customer via Paypal.
<HR><B>Customer Information:</B><BR><BR><B>Name: </B>" . $firstname . " " . $lastname . "\n <BR>" .
"<B>Email Address: </B>" . $email . "\n <BR>" .
"<B>Phone: </B>" . $phone . "\n <BR><BR>" .
"<B>Address: </B>" . $address . "\n <BR>" .
"<B>Address2: </B>" .$address2 . "\n <BR>" .
"<B>City: </B>" . $city . "\n <BR>" .
"<B>State: </B>" . $state . "\n <BR>" .
"<B>Zip: </B>" . $zip . "\n <BR><BR><HR><B>Ice Cream Cake Information:</B><BR><BR>" .
"<B>Cake Needed By: </B>" . $cake_needed_by . "\n <BR>" .
"<B>Cake Size: </B>" . $cake_size . "\n <BR>" .
"<B>Cake Flavor: </B>" . $cake_flavor . "\n <BR>" .
"<B>Decorations/Requests: </B>" . $requests);
$headers = $headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: " . $email . "\r\n";
mail("example@example.com", "New Ice Cream Cake Order!", $body, $headers);
echo "<BR><P>Thank You. Your tates old fashioned ice cream cake order has been sent. You will receive a phone call from tates old fashioned ice cream to confirm this order.</P>";
}
function handleform()
{
$errors = 0;
if (!trim($firstname))
{
echo "<BR><B>First Name</B>is required.";
$errors++;
}
if (!trim($lastname))
{
echo "<BR><B>Last Name</B>is required.";
$errors++;
}
if (!ereg ("^([a-zA-Z0-9_.-]*@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]*)$",stripslashes(trim($email))))
{
echo "<BR><B>Valid Email</B>is required.";
$errors++;
}
if ($errors > 0)
echo "<P>Please go back and and correct ";
if ($errors == 1)
echo "the error, ";
if ($errors > 1)
echo "the errors, ";
if ($errors > 0)
echo "and re-submit the form.";
else email_order();
}
if ($beensubmitted)
{
handleform();
}
?>
<DIV ALIGN="CENTER">
<FORM METHOD="POST" ACTION="test.php">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="610">
<TR>
<TD COLSPAN="2" WIDTH="110">First Name:</TD>
<TD COLSPAN="2" WIDTH="300"><INPUT TYPE="TEXT" SIZE="30" MAXLENGTH="30" NAME="firstname"></TD>
<TD ROWSPAN="11" WIDTH="200" VALIGN="MIDDLE" ALIGN="CENTER"><IMG SRC="http://tatesicecream.com/images/cakesA.jpg"></TD>
</TR>
<TR>
<TD COLSPAN="2">Last Name:</TD>
<TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="30" MAXLENGTH="30" NAME="lastname"></TD>
</TR>
<TR>
<TD COLSPAN="2">Email Address:</TD>
<TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="30" MAXLENGTH="50" NAME="email">
</TR>
<TR>
<TD COLSPAN="2">Phone Number:</TD>
<TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="10" MAXLENGTH="12" NAME="phone"> ex. 630-555-1234
</TR>
<TR>
<TD COLSPAN="2">Address:</TD>
<TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="30" MAXLENGTH="50" NAME="address">
</TR>
<TR>
<TD COLSPAN="2">Address 2:</TD>
<TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="30" MAXLENGTH="50" NAME="address2">
</TR>
<TR>
<TD COLSPAN="2">City:</TD>
<TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="30" MAXLENGTH="50" NAME="city">
</TR>
<TR>
<TD COLSPAN="2">State:</TD>
<TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="2" MAXLENGTH="2" NAME="state"> ex. IL
</TR>
<TR>
<TD COLSPAN="2">Zip Code:</TD>
<TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="5" MAXLENGTH="5" NAME="zip"> ex. 60187
</TR>
<TR>
<TD COLSPAN="2">Date Needed By:</TD>
<TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="8" MAXLENGTH="8" NAME="cake_needed_by"> mm/dd/yy
</TR>
<TR>
<TD COLSPAN="2">Cake Size:</TD>
<TD COLSPAN="2"><INPUT TYPE="radio" NAME="cake_size" VALUE="9-inch Round Cake">9-inch Round Cake
<INPUT TYPE="radio" NAME="cake_size" VALUE="9x13-inch Sheet Cake">9x13-inch Sheet Cake
</SELECT>
</TR>
<TR>
<TD COLSPAN="2">Cake Flavor:</TD>
<TD COLSPAN="2"><SELECT NAME="cake_flavor" SIZE="1">
<OPTION>Banana</OPTION>
<OPTION>Birthday Cake</OPTION>
<OPTION>Black Cherry</OPTION>
<OPTION>Bubble Gum</OPTION>
<OPTION>Blueberry Hill</OPTION>
<OPTION>Butter Pecan</OPTION>
<OPTION>Caramel Java Express</OPTION>
<OPTION>Chocolate</OPTION>
<OPTION>Chocolate Almond</OPTION>
<OPTION>Chocolate Chip</OPTION>
<OPTION>Chocolate Chip Mint</OPTION>
<OPTION>Chocolate Peanut Butter</OPTION>
<OPTION>Cinnamon</OPTION>
<OPTION>Coconut</OPTION>
<OPTION>Coffee</OPTION>
<OPTION>Cookie Dough</OPTION>
<OPTION>Cotton Candy</OPTION>
<OPTION>Dreamsicle</OPTION>
<OPTION>Frandango</OPTION>
<OPTION>Fudgie Brownie</OPTION>
<OPTION>Fudge Ripple</OPTION>
<OPTION>German Chocolate Cake</OPTION>
<OPTION>Heath Bar Crunch</OPTION>
<OPTION>Irish Mocha Chip</OPTION>
<OPTION>Maple Walnut</OPTION>
<OPTION>Mint Meltaway</OPTION>
<OPTION>New York Cherry</OPTION>
<OPTION>Oreo Smash</OPTION>
<OPTION>Pecan Praline</OPTION>
<OPTION>Peppermint</OPTION>
<OPTION>Pistachio Almond</OPTION>
<OPTION>Pumpkin</OPTION>
<OPTION>Raspberry Fudge Chunk</OPTION>
<OPTION>Rum Raisin</OPTION>
<OPTION>Strawberry</OPTION>
<OPTION>Train Tracks</OPTION>
<OPTION>Triple Chocolate</OPTION>
<OPTION>Vanilla</OPTION>
</SELECT>
<TD ROWSPAN="4" VALIGN="MIDDLE" ALIGN="CENTER"><IMG SRC="http://tatesicecream.com/images/cakesB.jpg"></TD>
</TR>
<TR>
<TD COLSPAN="2">Cake Decoration:</TD>
<TD COLSPAN="2"><TEXTAREA ROWS="10" COLS="30" NAME="requests" WRAP="PHYSICAL"/>Please enter a brief description of how you would like us to decorate your Ice Cream Cake and/or any special requests.</TEXTAREA>
</TR>
<TR>
<TD COLSPAN="2"><BR></TD>
<TD COLSPAN="2"><BR>
</TR>
<TR>
<TD COLSPAN="2"></TD>
<TD COLSPAN="2">
<BR><INPUT TYPE="HIDDEN" NAME="beensubmitted" VALUE="TRUE">
<INPUT TYPE="SUBMIT" VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Reset">
</TD>
</TR>
</FORM>
</TABLE>
<P>Tates Ice Cream uses:</P>
<img align="middle" src="https://www.paypal.com/en_US/i/bnr/bnr_paymentsBy_150x40.gif" border="0">
</DIV>
</FORM>
</BODY>
</HTML>