newbie help with php form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dieselx
Forum Newbie
Posts: 2
Joined: Wed Mar 31, 2004 1:35 pm

newbie help with php form

Post by dieselx »

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.");
}


?>
*************************************************************
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

ANNNNNNNNND whats the problem?
dieselx
Forum Newbie
Posts: 2
Joined: Wed Mar 31, 2004 1:35 pm

Post by dieselx »

Error handling does not seem to work. It should list all the fields that have not been filled out correctly.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

I don't see any $_POST/$_GET variables defined... that is if you have register_globals off which you should. It's the default, so unless you changed something...

Also, an error there is you have $prob[$count] which, in any case, should be $prob["$count"]; .
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

You keep setting $prob[$count] but what is this $count variable? I don't see it being set anywhere. Then you use $c to find the index in $prob where the error is, but I'm not sure where in $prob the error codes are going because I don't know what the value of $count is. I think you want to change $prob[$count] ="whatver" to $prob[$c] = "whatever"
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Diesel- there are a few different ways of doing this. If you are new to PHP, I would suggest a less complicated method. :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Steveo31 wrote:Also, an error there is you have $prob[$count] which, in any case, should be $prob["$count"]; .
That is not an error - $prob[$count] is better than $prob["$count"] - you don't need to quote variable names.

Mac
Post Reply