Jump to content

php contact form


jhart82

Recommended Posts

been struggling with this. i'm testing with safari + firefox on mac. the page loads fine (no errors) and shows the form. but when submitted, it doesn't display the errors if those fields aren't filled in.

 

<?
$form_block = "
<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<form method=\"post\" action=\"$_SERVER[php_SELF]\">

<tr><td>Name</td><td><input name=\"name\" type=\"text\" value=\"$name\" size=\"30\" /></td></tr>

<tr><td>Email</td><td><input name=\"email\" type=\"text\" value=\"$email\" size=\"30\" /></td></tr>

<tr><td>Phone</td><td><input name=\"phone\" type=\"text\" value=\"$phone\" size=\"30\" /></td></tr>

<tr><td>Company</td><td><input name=\"company\" type=\"text\" value=\"$company\" size=\"30\" /></td></tr>

<tr><td>Street Address</td><td><input name=\"address\" type=\"text\" value=\"$address\" size=\"30\" /></td></tr>

<tr><td>City, State, Zip</td><td><input name=\"city\" type=\"text\" value=\"$city\" size=\"15\" /><input name=\"state\" type=\"text\" value=\"$state\" size=\"3\" /><input name=\"zip\" type=\"text\" value=\"$zip\" size=\"5\" /></td></tr>

<tr><td>Office Trailer Address</td><td><input name=\"traileraddress\" type=\"text\" value=\"$traileraddress\" size=\"30\" /></td></tr>

<tr><td>Office Trailer City, State, Zip</td><td><input name=\"city2\" type=\"text\" value=\"$city2\" size=\"15\" /><input name=\"state2\" type=\"text\" value=\"$state2\" size=\"3\" /><input name=\"zip2\" type=\"text\" value=\"$zip2\" size=\"5\" /></td></tr>

<tr><td>What size  trailer do you think will be most appropriate for you?</td><td><input name=\"trailersize\" type=\"text\" value=\"$trailersize\" size=\"30\" /></td></tr>

<tr><td>Would you like to lease or purchase the  trailer?</td><td><input type=\"checkbox\" name=\"lease\" value=\"$lease\" />Lease <input type=\"checkbox\" name=\"purchase\" value=\"$purchase\" /> Purchase</td></tr>

<tr><td>If lease, how long do you anticipate needing the trailer?</td><td><input name=\"lease2\" type=\"text\" value=\"$lease2\" size=\"30\" /></td></tr>

<tr><td>Questions/Comments:</td><td><textarea name=\"qc\" cols=\"30\" rows=\"6\" value=\"$qc\"></textarea></td></tr>

<tr><td valign=\"top\"><input type=\"hidden\" name=\"op\" value=\"ds\"><input type=\"submit\" value=\"Send Quote Request\" /></td><td> </td></tr>

</table>
</form>
";

if ($op != "ds") {

echo "$form_block";
    
} else if ($op == "ds") {

if ($name == "") {
$name_err = "<font color=red>please fill in your name</font><br>"; 
$send = 0;
}
if ($email == "") {
$email_err = "<font color=red>please fill in your email</font><br>";
$send = 0;
}
if ($phone == "") {
$phone_err = "<font color=red>please fill in your phone</font><br>";
$send = 0;
}
if ($city == "") {
$city_err = "<font color=red>please fill in your city</font><br>";
$send = 0;
}
if ($state == "") {
$state_err = "<font color=red>please fill in your state</font><br>";
$send = 0;
} 

if ($send != "0") {
$msg .= "name: $name\n";
$msg .= "email: $email\n";
$msg .= "phone: $phone\n";
$msg .= "company: $company\n";
$msg .= "street address: $address\n";
$msg .= "city: $city\n";
$msg .= "state: $state\n";
$msg .= "zip: $zip\n";
$msg .= "traileraddress: $traileraddress\n";
$msg .= "trailer city: $city2\n";
$msg .= "trailer state: $state2\n";
$msg .= "trailer zip: $zip2\n";
$msg .= "trailer size: $trailersize\n";
$msg .= "lease or purchase: $lease $lease2 $purchase\n";
$msg .= "questions/comments: $qc";    
$to = "test@test.com";
$subject = "test";

mail($to, $subject, $msg);

echo "Thank you for your interest. We will be in contact with you shortly.";

} else if ($send == "0") {
echo "$name_err";
echo "$email_err";
echo "$phone_err";
echo "$city_err";
echo "$state_err";
echo "$form_block";  
}     
}
?>

Link to comment
Share on other sites

Try playing around with array variables.

 

if(!$this){ //$this is not set
$err[] = "Errror One";
}

if(!$that){ //$that is not set
$err[] = "Error Two";
}

//etc....

if(is_array($err)){
  foreach($err AS $errors){
    echo "<font color=\"red\">$errors</font><br />\n";
  }
}else {
echo "OMG IT WORKED.\n";
}

Link to comment
Share on other sites

ok got it working except for the checkbox. need to have it see which one was checked then print that in the email. any ideas?

 

<tr><td>Would you like to lease or purchase the container?</td><td><input type=\"checkbox\" name=\"lease\" value=\"lease\" />Lease <input type=\"checkbox\" name=\"purchase\" value=\"purchase\" /> Purchase</td></tr>

 

$msg .= "lease or purchase: $_POST[lease] $_POST[lease2] $_POST[purchase]\n";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.