I've looked at the snippet libraries and found some good examples,
EmailHandler, mailform, and Lloyds "enquiry" form etc etc.
All are excellent, however over complex.
I've decided to work with the emailhandler form from the old snippet library.
http://www.etomite.com/browsesnippets.html...;lst_category=3
This seems the easiest to work with to modify.
I'm trying to modify some of the fields and add some additional fields.
So for example, the default form provides
1.) Your name
2.) Your Email Address
3.) Your Message
I'd like to do
1.) Your Name
2.) Your Email Address
3.) date you would like to attend (doesn't have to be a date field - just text)
4.) time you would like to attend (as above)
5.) number of people in your party.
Now in theory - this looks quite simple to do, add some fields and append them together for the message var
I've modified the existing code
$sendemail =
isset($_POST['sendemail']) && $_POST['sendemail']!= "{{" && $_POST['sendemail']!= "[[" &&
$_POST['sendemail']!= "[(" && $_POST['sendemail']!= "[~" && $_POST['sendemail']!= "[*" ?
$_POST['sendemail'] : "";
$name =
isset($_POST['name']) && $_POST['name']!= "{{" && $_POST['name']!= "[[" &&
$_POST['name']!= "[(" && $_POST['name']!= "[~" && $_POST['name']!= "[*" ?
$_POST['name'] : "";
$email =
isset($_POST['email']) && $_POST['email']!= "{{" && $_POST['email']!= "[[" &&
$_POST['email']!= "[(" && $_POST['email']!= "[~" && $_POST['email']!= "[*" ?
$_POST['email'] : "";
$subject =
isset($_POST['subject']) && $_POST['subject']!= "{{" && $_POST['subject']!= "[[" &&
$_POST['subject']!= "[(" && $_POST['subject']!= "[~" && $_POST['subject']!= "[*" ?
$_POST['subject'] : "";
$message =
isset($_POST['message']) && $_POST['message']!= "{{" && $_POST['message']!= "[[" &&
$_POST['message']!= "[(" && $_POST['message']!= "[~" && $_POST['message']!= "[*" ?
$_POST['message'] : "";
// check errors
$pattern = ".+@.+..+";
$error = '<font color="#FF0000">Required</font><br>';
$bad_email = '<font color="#FF0000">Make sure that you have entered a valid e-mail address.</font><br>';
if($sendemail=="sendemail"){
if($name==""){$name_error = $error;}
if($email==""){$email_error = $error;}
elseif(!eregi($pattern,$email)){$email_error = $bad_email;}
if($subject==""){$subject_error = $error;}
if($message==""){$message_error = $error;}
}
if(($name!="")&&(eregi($pattern,$email))&&($subject!="")&&($message!="")){
if($_SERVER["HTTP_HOST"] != "benreeves"){mail($to, $subject, $message, "From: $email");}
$EmailHandler = "<b>Your message has been sent.</b><p>You will recieve feedback as soon as possible.";
} else {
$EmailHandler .= "<b>Use the form below to contact via e-mail.</b>rn";
$EmailHandler .= '<form name="EmailHandler" action="" method="post">';
$EmailHandler .= '<input name="sendemail" type="hidden" value="sendemail">';
$EmailHandler .= '<p>'.$name_error.'<b>Your Name:</b><br><input type="text" name="name" class="text" value="'.$name.'">';
$EmailHandler .= '<p>'.$email_error.'<b>Your e-mail address:</b><br><input type="text" name="email" class="text" value="'.$email.'">';
$EmailHandler .= '<p>'.$subject_error.'<b>Subject:</b><br><input type="text" name="subject" class="text" value="'.$subject.'">';
$EmailHandler .= '<p>'.$message_error.'<b>Message:</b><br><textarea name="message" rows=5 cols=50 wrap="off">'.$message.'</textarea>';
$EmailHandler .= '<p><input type="submit" name="sub" class="button" value="Submit">';
$EmailHandler .= '</form>';
}
return $EmailHandler;
to
$sendemail =
isset($_POST['sendemail']) && $_POST['sendemail']!= "{{" && $_POST['sendemail']!= "[[" &&
$_POST['sendemail']!= "[(" && $_POST['sendemail']!= "[~" && $_POST['sendemail']!= "[*" ?
$_POST['sendemail'] : "";
$name =
isset($_POST['name']) && $_POST['name']!= "{{" && $_POST['name']!= "[[" &&
$_POST['name']!= "[(" && $_POST['name']!= "[~" && $_POST['name']!= "[*" ?
$_POST['name'] : "";
$email =
isset($_POST['email']) && $_POST['email']!= "{{" && $_POST['email']!= "[[" &&
$_POST['email']!= "[(" && $_POST['email']!= "[~" && $_POST['email']!= "[*" ?
$_POST['email'] : "";
$subject =
isset($_POST['subject']) && $_POST['subject']!= "{{" && $_POST['subject']!= "[[" &&
$_POST['subject']!= "[(" && $_POST['subject']!= "[~" && $_POST['subject']!= "[*" ?
$_POST['subject'] : "";
$telno =
isset($_POST['telno']) && $_POST['telno']!= "{{" && $_POST['telno']!= "[[" &&
$_POST['telno']!= "[(" && $_POST['telno']!= "[~" && $_POST['telno']!= "[*" ?
$_POST['telno'] : "";
$date =
isset($_POST['date']) && $_POST['date']!= "{{" && $_POST['date']!= "[[" &&
$_POST['date']!= "[(" && $_POST['date']!= "[~" && $_POST['date']!= "[*" ?
$_POST['date'] : "";
$time =
isset($_POST['time']) && $_POST['time']!= "{{" && $_POST['time']!= "[[" &&
$_POST['time']!= "[(" && $_POST['time']!= "[~" && $_POST['time']!= "[*" ?
$_POST['time'] : "";
$attend =
isset($_POST['attend']) && $_POST['attend']!= "{{" && $_POST['attend']!= "[[" &&
$_POST['attend']!= "[(" && $_POST['attend']!= "[~" && $_POST['attend']!= "[*" ?
$_POST['attend'] : "";
$message =
isset($_POST['message']) && $_POST['message']!= "{{" && $_POST['message']!= "[[" &&
$_POST['message']!= "[(" && $_POST['message']!= "[~" && $_POST['message']!= "[*" ?
$_POST['message'] : "";
// check errors
$pattern = ".+@.+..+";
$error = '<font color="#FF0000">Required</font><br>';
$bad_email = '<font color="#FF0000">Make sure that you have entered a valid e-mail address.</font><br>';
if($sendemail=="sendemail"){
if($name==""){$name_error = $error;}
if($email==""){$email_error = $error;}
elseif(!eregi($pattern,$email)){$email_error = $bad_email;}
// if($subject==""){$subject_error = $error;}
// if($message==""){$message_error = $error;}
}
if(($name!="")&&(eregi($pattern,$email))&&($subject!="")&&($message!="")){
if($_SERVER["HTTP_HOST"] != "benreeves"){mail($to, $subject, $message, "From: $email");}
$EmailHandler = "<b>Your message has been sent.</b><p>You will recieve feedback as soon as possible.";
} else {
$EmailHandler .= "<b>Use the form below to make a free booking request via the site.</b>\n";
$EmailHandler .= '<form name="EmailHandler" action="" method="post">';
$EmailHandler .= '<input name="sendemail" type="hidden" value="sendemail">';
$EmailHandler .= '<p>'.$name_error.'<b>Your Name:</b><br><input type="text" name="name" class="text" value="'.$name.'">';
$EmailHandler .= '<p>'.$email_error.'<b>Your e-mail address:</b><br><input type="text" name="email" class="text" value="'.$email.'">';
$EmailHandler .= '<p>'.$subjet_error.'<b>Your contact telephone number</b><br><input type="text" name="telno" class="text" value="'.$telno.'">';
$EmailHandler .= '<p>'.$subjet_error.'<b>Booking date requested</b><br><input type="text" name="date" class="text" value="'.$date.'">';
$EmailHandler .= '<p>'.$subjet_error.'<b>Booking time requested</b><br><input type="text" name="time" class="text" value="'.$time.'">';
$EmailHandler .= '<p>'.$subjet_error.'<b>Number of attendees</b><br><input type="text" name="attend" class="text" value="'.$attend.'">';
$subject = 'FF1600 Fee event Web Booking';
$message = $telno.$date.$time.$attend;
$EmailHandler .= '<p><input type="submit" name="sub" class="button" value="Submit">';
$EmailHandler .= '</form>';
}
return $EmailHandler;
I can see why this has gone wrong.
1.) by changing the value of the message box, that code that checks if the message box is populated is broke
2.) I've tried to append together the output of the firleds telno date time attend ( I forgot to say I also wanted to add a telephone number field) Not only do I believe I have done this wrong, I'd also like to do this a little better so the email is formated with
Hi $name, would like to book $attend at $time on $date for the FF1600 free event. You can contact him on $telno
so that its easier for the person reading to make sense of.
But first things first I need to fix what I've broke. Before I actually try to start fixing I'd like to understand am I correct in why/how I've broke this form ?
How can I maintain the error checking on name, and the valid email checker on the email, plus add the same "must be populated" error checking to the other fields ?
Thanks for your time
Edited by ikonia, 29 October 2007 - 11:43 AM.










