newbie help with php form
Posted: Wed Mar 31, 2004 1:35 pm
Hey everyone, thanks for any help in advance. I am new to php and working on trying to get my forms to work. I currently have three forms and they are all parsed by one php script. My error handling does not seem to be working.
here is an example of one of the forms http://mirabellavillas.com/mortage2.htm
name of forms:
contact,
mortgage,
realtor
formprocess2.php (php script)
***********************************************************
<?php
$sendable = true;
$c = 0;
$ToEmail = "pgallego20@hotmail.com";
?>
<?php
if ($type == "contact") {
print ("About Mirabella Villas");
}
else if ($type == "mortgage") {
print ("Mortgage Lending Program");
}
else if($type == "realtor") {
print ("Realtor Center");
?>
<?php
//==============
//============== CHECK FOR ERRORS
//==============
//CONTACT
if ($type == "contact")
{
if (strlen($name) < 1)
{
$sendable = false;
$prob[$count] = "Name";
$c++;
}
if (strlen($email) < 1)
{
$sendable = false;
$prob[$count] = "Email";
$c++;
}
if (strlen($address) < 1)
{
$sendable = false;
$prob[$count] = "Address";
$c++;
}
if (strlen($city) < 1)
{
$sendable = false;
$prob[$count] = "City";
$c++;
}
if (strlen($state) < 1)
{
$sendable = false;
$prob[$count] = "State";
$c++;
}
if (strlen($zipcode) < 1)
{
$sendable = false;
$prob[$count] = "Zip Code";
$c++;
}
if (strlen($phone) < 1)
{
$sendable = false;
$prob[$count] = "Phone Number";
$c++;
}
}
//MORTGAGE
else if ($type == "mortgage")
{
if (strlen($name) < 1)
{
$sendable = false;
$prob[$count] = "Name";
$c++;
}
if (strlen($email) < 1)
{
$sendable = false;
$prob[$count] = "Email";
$c++;
}
if (strlen($address) < 1)
{
$sendable = false;
$prob[$count] = "Address";
$c++;
}
if (strlen($city) < 1)
{
$sendable = false;
$prob[$count] = "City";
$c++;
}
if (strlen($state) < 1)
{
$sendable = false;
$prob[$count] = "State";
$c++;
}
if (strlen($zipcode) < 1)
{
$sendable = false;
$prob[$count] = "Zip Code";
$c++;
}
if (strlen($phone) < 1)
{
$sendable = false;
$prob[$count] = "Phone Number";
$c++;
}
}
//REALTOR
else if($type == "realtor")
{
if (strlen($name) < 1)
{
$sendable = false;
$prob[$count] = "Name";
$c++;
}
if (strlen($email) < 1)
{
$sendable = false;
$prob[$count] = "Email";
$c++;
}
if (strlen($address) < 1)
{
$sendable = false;
$prob[$count] = "Address";
$c++;
}
if (strlen($city) < 1)
{
$sendable = false;
$prob[$count] = "City";
$c++;
}
if (strlen($state) < 1)
{
$sendable = false;
$prob[$count] = "State";
$c++;
}
if (strlen($zipcode) < 1)
{
$sendable = false;
$prob[$count] = "Zip Code";
$c++;
}
if (strlen($phone) < 1)
{
$sendable = false;
$prob[$count] = "Phone Number";
$c++;
}
if (strlen($firm) < 1)
{
$sendable = false;
$prob[$count] = "Firm Name";
$c++;
}
}
//==============
//============== ERROR REPORT
//==============
if (!$sendable)
{
print ("<b>The following errors were found in your request.");
print ("Please press the back button on your broweser to go back and fill out all required fields correctly</b>");
for ($i=0;$i<$c;$i++)
{
echo ("- ".$prob[$c]."<br>");
}
}
//==============
//============== SENDABLE
//==============
else if ($sendable)
{
if ($type == "contact")
{
$subject = "Information request sent from Mirabilla Villas website";
$EmailBody = "CONTACT INFORMATION\nName: $name\nEmail: $email\nStreet Address: $address\nCity: $city\nState: $state\nZip code: $zipcode\nPhone Number: $phone
QUESTIONNAIRE\nHow did you hear about us: $select1\nWhen do you plan to move: $select2
Type of home: $select3\nPrice range: $select4\nType of community: $select5
ADDITIONAL INFORMATION DESIRED (if any)\nMortgage Information: $mortgageinfo\nMoving Company: $movecomp\nTitle/Insurance/Assistance: $title
COMMENTS\n$comments";
$EmailFooter="\n\nThis message was sent by: $name from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at http://www.mirabellavillas.com";
mail($ToName." <".$ToEmail.">",$subject, $EmailBody, "From: ".$name." <".$email.">");
}
else if ($type == "mortgage")
{
$subject = "Information request sent from Mirabilla Villas website";
$EmailBody = "Mortgage INFORMATION\nName: $name\nEmail: $email\nStreet Address: $address\nCity: $city\nState: $state\nZip code: $zipcode\nPhone Number: $phone
COMMENTS\n$comments";
$EmailFooter="\n\nThis message was sent by: $name from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at http://www.mirabellavillas.com";
mail($ToName." <".$ToEmail.">",$subject, $EmailBody, "From: ".$name." <".$email.">");
}
else if($type == "realtor")
{
$subject = "Realtor Registration";
$EmailBody = "CONTACT INFORMATION:\nName: $name\nFirm: $firm\nBroker or Agent: $firmtype\nEmail: $email\nStreet Address: $address\nCity: $city\nState: $state\nZip code: $zipcode\nPhone Number: $phone
COMMENTS\n$comments";
$EmailFooter="\n\nThis message was sent by: $name from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at http://www.mirabellavillas.com";
mail($ToName." <".$ToEmail.">",$subject, $EmailBody, "From: ".$name." <".$email.">");
}
print ("Thank you. Your request has been sent.");
}
?>
*************************************************************
here is an example of one of the forms http://mirabellavillas.com/mortage2.htm
name of forms:
contact,
mortgage,
realtor
formprocess2.php (php script)
***********************************************************
<?php
$sendable = true;
$c = 0;
$ToEmail = "pgallego20@hotmail.com";
?>
<?php
if ($type == "contact") {
print ("About Mirabella Villas");
}
else if ($type == "mortgage") {
print ("Mortgage Lending Program");
}
else if($type == "realtor") {
print ("Realtor Center");
?>
<?php
//==============
//============== CHECK FOR ERRORS
//==============
//CONTACT
if ($type == "contact")
{
if (strlen($name) < 1)
{
$sendable = false;
$prob[$count] = "Name";
$c++;
}
if (strlen($email) < 1)
{
$sendable = false;
$prob[$count] = "Email";
$c++;
}
if (strlen($address) < 1)
{
$sendable = false;
$prob[$count] = "Address";
$c++;
}
if (strlen($city) < 1)
{
$sendable = false;
$prob[$count] = "City";
$c++;
}
if (strlen($state) < 1)
{
$sendable = false;
$prob[$count] = "State";
$c++;
}
if (strlen($zipcode) < 1)
{
$sendable = false;
$prob[$count] = "Zip Code";
$c++;
}
if (strlen($phone) < 1)
{
$sendable = false;
$prob[$count] = "Phone Number";
$c++;
}
}
//MORTGAGE
else if ($type == "mortgage")
{
if (strlen($name) < 1)
{
$sendable = false;
$prob[$count] = "Name";
$c++;
}
if (strlen($email) < 1)
{
$sendable = false;
$prob[$count] = "Email";
$c++;
}
if (strlen($address) < 1)
{
$sendable = false;
$prob[$count] = "Address";
$c++;
}
if (strlen($city) < 1)
{
$sendable = false;
$prob[$count] = "City";
$c++;
}
if (strlen($state) < 1)
{
$sendable = false;
$prob[$count] = "State";
$c++;
}
if (strlen($zipcode) < 1)
{
$sendable = false;
$prob[$count] = "Zip Code";
$c++;
}
if (strlen($phone) < 1)
{
$sendable = false;
$prob[$count] = "Phone Number";
$c++;
}
}
//REALTOR
else if($type == "realtor")
{
if (strlen($name) < 1)
{
$sendable = false;
$prob[$count] = "Name";
$c++;
}
if (strlen($email) < 1)
{
$sendable = false;
$prob[$count] = "Email";
$c++;
}
if (strlen($address) < 1)
{
$sendable = false;
$prob[$count] = "Address";
$c++;
}
if (strlen($city) < 1)
{
$sendable = false;
$prob[$count] = "City";
$c++;
}
if (strlen($state) < 1)
{
$sendable = false;
$prob[$count] = "State";
$c++;
}
if (strlen($zipcode) < 1)
{
$sendable = false;
$prob[$count] = "Zip Code";
$c++;
}
if (strlen($phone) < 1)
{
$sendable = false;
$prob[$count] = "Phone Number";
$c++;
}
if (strlen($firm) < 1)
{
$sendable = false;
$prob[$count] = "Firm Name";
$c++;
}
}
//==============
//============== ERROR REPORT
//==============
if (!$sendable)
{
print ("<b>The following errors were found in your request.");
print ("Please press the back button on your broweser to go back and fill out all required fields correctly</b>");
for ($i=0;$i<$c;$i++)
{
echo ("- ".$prob[$c]."<br>");
}
}
//==============
//============== SENDABLE
//==============
else if ($sendable)
{
if ($type == "contact")
{
$subject = "Information request sent from Mirabilla Villas website";
$EmailBody = "CONTACT INFORMATION\nName: $name\nEmail: $email\nStreet Address: $address\nCity: $city\nState: $state\nZip code: $zipcode\nPhone Number: $phone
QUESTIONNAIRE\nHow did you hear about us: $select1\nWhen do you plan to move: $select2
Type of home: $select3\nPrice range: $select4\nType of community: $select5
ADDITIONAL INFORMATION DESIRED (if any)\nMortgage Information: $mortgageinfo\nMoving Company: $movecomp\nTitle/Insurance/Assistance: $title
COMMENTS\n$comments";
$EmailFooter="\n\nThis message was sent by: $name from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at http://www.mirabellavillas.com";
mail($ToName." <".$ToEmail.">",$subject, $EmailBody, "From: ".$name." <".$email.">");
}
else if ($type == "mortgage")
{
$subject = "Information request sent from Mirabilla Villas website";
$EmailBody = "Mortgage INFORMATION\nName: $name\nEmail: $email\nStreet Address: $address\nCity: $city\nState: $state\nZip code: $zipcode\nPhone Number: $phone
COMMENTS\n$comments";
$EmailFooter="\n\nThis message was sent by: $name from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at http://www.mirabellavillas.com";
mail($ToName." <".$ToEmail.">",$subject, $EmailBody, "From: ".$name." <".$email.">");
}
else if($type == "realtor")
{
$subject = "Realtor Registration";
$EmailBody = "CONTACT INFORMATION:\nName: $name\nFirm: $firm\nBroker or Agent: $firmtype\nEmail: $email\nStreet Address: $address\nCity: $city\nState: $state\nZip code: $zipcode\nPhone Number: $phone
COMMENTS\n$comments";
$EmailFooter="\n\nThis message was sent by: $name from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at http://www.mirabellavillas.com";
mail($ToName." <".$ToEmail.">",$subject, $EmailBody, "From: ".$name." <".$email.">");
}
print ("Thank you. Your request has been sent.");
}
?>
*************************************************************