I'm trying to make a form for a website I'm building. I'm very new to coding but I have done some simple websites before and have a very basic knowledge of web coding. I have two issues. 1) I'm trying to code this form so that if the two email fields do not match, a message will show up in some way notifying the viewer. 2) The send button will send the info in an email but two parts aren't working: the check box array isn't working (it only says "array" and I want it to say the values separated by commas), and I don't know how to have it redirect to a separate success page (i.e. contact_success.html). Giving me the answer alone is fine, but it would be really great if you can tell me why you use the specific codes.
Here is the HTML code for the entire form:
<form name="contact" action="contactProcess.php" method="post" onSubmit="return validateForm()">
<table width="100%" cellspacing="6">
<tr>
<th width="30%" class="th_contact">*Name:</th>
<td width="70%"><input type="text" size="50" name="name"></td>
</tr>
<tr>
<th class="th_contact">*Your email address:</th>
<td><input type="text" size="50" name="email"></td>
</tr>
<tr>
<th class="th_contact">*Confirm email address:</th>
<td><input type="text" size="50" name="email2"></td>
</tr>
<tr>
<th class="th_contact">How did you hear about us?</th>
<td><input type="radio" name="referral" value="friend or family">Friend or Family<br />
<input type="radio" name="referral" value="veterinarian">Veterinarian<br />
<input type="radio" name="referral" value="flyer or mailer">Flyer or Mailer<br />
<input type="radio" name="referral" value="humane society or similar facility">Humane Society or Similar Facility<br />
<input type="radio" name="referral" value="walked or drove by">Walked or Drove By<br />
<input type="radio" name="referral" value="other">Other<br />
</td>
</tr>
<tr>
<th valign="top"><h5>What type of pet do you have?</h5></th>
<td><input type="checkbox" name="pet[]" value="dog">Dog<br />
<input type="checkbox" name="pet[]" value="cat">Cat<br />
<input type="checkbox" name="pet[]" value="bird">Bird<br />
<input type="checkbox" name="pet[]" value="fish">Fish<br />
<input type="checkbox" name="pet[]" value="reptile">Reptile<br />
<input type="checkbox" name="pet[]" value="small animal">Small Animal<br />
</td>
</tr>
<td align="left"><input type="submit" class="button" value="submit">
*Required Fields</td>
</tr>
</table>
</form>
Here's the PHP:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact PHP</title>
<link href="A4P.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php {
//Set up message body
$message = "Form Submitted on: " . date("m/d/y") . "\n";
$message .= "\n";
$message .= "Name: " . $_POST['name'] . "\n";
$message .= "Email Address: " . $_POST['email'] . "\n\n";
$message .= "Referred by: " . stripslashes($_POST['referral']) . "\n";
$message .= "Pets: " . $_POST['pet'];
//Set up email
$to = "example@example.com, <" . $_POST['email'] . ">";
$subject = "New Email Club Entry";
$headers = "From: " . "All 4 Pets Website";
//Send email
mail($to,$subject,$message,$headers);
}
?>
</body>
</html>
Here's how the email looks in case it matters:
Form Submitted on: 11/18/13
Name: Brad Moore
Email Address: 123@yahoo.com
Referred by: walked or drove by
Pets: Array