<form name="contactform" method="post" action="send_form_email.php">
<!--Name input-->
<input placeholder="Full Name *" type="text" name="name" maxlength="50">
<br />
<!--Email input-->
<input placeholder="Email Address *" type="email" name="email" maxlength="80">
<br />
<!--Phone number input (not required)-->
<input placeholder="Telephone Number" type="tel" name="telephone" maxlength="15">
<br />
<!--Company name input (not required)-->
<input placeholder="Company" type="text" name="company" maxlength="50">
<br />
<!--Comments & messege input-->
<textarea placeholder="Please include as much information as possible *" name="comments" maxlength="500" cols="25" rows="5"></textarea>
<br />
<!--Check for privacy policy-->
<label class="GDRP">
I consent to having this website store my submitted information so they can respond to my inquiry.
<input type="checkbox" name="GDRP">
</label>
<!--Submit button-->
<input type="submit" value="SUBMIT">
</form>
This is my HTML - I don't know how important it is to helping me find a solution but I figured, why not. I tried cleaning it up so you can get through with helping me as quick as possible. The only important fields are the 'name', 'email', 'comments' and the question at matter 'GDRP'.
<?php if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "email#adress.com";
$email_subject = "www.Adress.com - CONTACT FORM";
function died($error) {
// error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted: ";
echo $error."<br />";
echo "Please fix these errors.";
die();
}
// validation expected data exists
if(
!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['company']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments']) ||
!isset($_POST['GDRP'])
) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$company = $_POST['company']; // not required
$comments = $_POST['comments']; // required
$GDRP = $_POST['GDRP']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= '<br /><br /><font color="red">Full Name</font><br /><br />';
}
if(!preg_match($email_exp,$email_from)) {
$error_message .= '<font color="red">Email Address</font><br /><br />';
}
if(strlen($comments) < 2) {
$error_message .= '<font color="red">Comments</font><br /><br />';
}
if(!empty($GDRP)) {
$error_message .= '<font color="red">GDRP Agreement</font><br /><br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<body>
Thank you for contacting us. We will be in touch with you as soon as possible.
</body>
<?php
}
?>
My problem is that the checkbox ('GDRP') isn't showing $error_message when it's not filled in. In fact, none show when 'GDRP' is empty. If you fill 'GDRP' but leave the others [required fields] empty all of their $error_message except for 'GDRP' will show.
if(!empty($GDRP)) { // if not empty
$error_message .= '<font color="red">GDRP Agreement</font><br /><br />';
}
looks like you are checking that $GDPR isn't empty, this should be the other way around.
change if(!empty($GDRP)) { to if(empty($GDRP)) {.
Only checked checkboxes send and available in POST. So, looks like in the following lines your script finished and other errors not shown:
!isset($_POST['GDRP'])
) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
Related
i"m new here and i don't understand php at all, but i need to do a contact form with checkbox and verification, this is my code ( is a frankenstein code).
I need that my form send an email with the information avoiding spam, and missing information, and when mail arrive has all the details in header like a mail to reply, subject and all.
if you can post an correct code will be wonderful.
thanks in advance
<form name="htmlform" method="post" action="app.php">
<label for="name">*Nombre Completo</label>
<input type="text" name="name" maxlength="150" size="50">
<label for="company">*Empresa</label>
<input type="text" name="company" maxlength="150" size="50">
<label for="telephone">Teléfono</label>
<input type="text" name="telephone" maxlength="150" size="50">
<label for="email">*Email</label>
<input type="text" name="email" maxlength="180" size="50">
<label for="services">*Servicios de Interes</label>
<input type="checkbox" name="services[]" value="apps" />apps<br />
<input type="checkbox" name="services[]" value="Marketing Movil" />Marketing Móvil<br />
<input type="checkbox" name="services[]" value="video juegos" />video Juegos<br />
<label for="comments">*Comentarios</label>
<textarea name="comments" maxlength="1000" cols="40" rows="6"></textarea>
<div class="hide">Leave this empty:<input name="url" /></div>
<center><input class="button large" type="submit" value="Submit Form"></center>
</form>
<?php
// if the url field is empty
if(isset($_POST['url']) && $_POST['url'] == '')
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "my#mail.com";
$email_subject = "Contact from web.com";
function died($error) {
// your error code can go here
echo "There were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['full_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['services']) ||
!isset($_POST['comments']))
{
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$full_name = $_POST['full_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // required
$services = $_POST['services']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$full_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Full Name: ".clean_string($full_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Services: ".clean_string($services)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
// hacker defense
function clean($var){//request string cleaner
if(get_magic_quotes_gpc()) $var=stripslashes($var); //clean
$var=mysql_real_escape_string($var); //clean
return strip_tags($var, '<b><a>');//returning clean var
}
function hackerDefense(){//thanks to Allen Sanford
// begin hacker defense
foreach ($_POST as &$postvalue){ //checking posts
$postvalue = clean($postvalue);//cleaning the value
}
} // end hacker defense
?>
<!-- include your own success html here -->
<center>
<img src="images/logo.png" />
<br>
<br>
Thank you for contacting us. We will be in touch.<br>
<br>
HOME</center>
<?php
}
?>
My form doesn't generate an E-Mail it just redirects me to a blank page.
i have my .php form in a folder named php on my server
thank you for your help.
here is my html code
<form id="form" method="post" action="php/send_form_email.php">
<fieldset>
<label><strong>Name:</strong>
<input type="text" value="">
</label>
<label><strong>Email:</strong>
<input type="text" value="">
</label>
<label><strong>Phone:</strong>
<input type="text" value="">
</label>
<label><strong>Message:</strong>
<textarea></textarea>
</label>
<div class="btns">ClearSend</div>
</fieldset>
</form>
here is the php code i'm using:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "###.com";
$email_subject = "havok security contact form";
function died($error) {
// your error code can go here
echo "We are very sorry, but there was an error found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['phone']; // not required
$comments = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'The Message you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Phone: ".clean_string($telephone)."\n";
$email_message .= "Message: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
The input type under email needs to have a name attribute called "email". Your PHP script is looking to see if $_POST["email"] is set, and it is not. So, this should work:
<form id="form" method="post" action="php/send_form_email.php">
<fieldset>
<label><strong>Name:</strong>
<input type="text" name="name" value="">
</label>
<label><strong>Email:</strong>
<input type="text" name="email" value="">
</label>
<label><strong>Phone:</strong>
<input type="text" name="phone" value="">
</label>
<label><strong>Message:</strong>
<textarea name = "message"></textarea>
</label>
<div class="btns">ClearSend</div>
</fieldset>
</form>
I have serached through previous questions and have had no luck finding the answer.
I want to simply send the imformation from my form to be e-mailed to me.here is my code for form.
<form action="http://bikesnwines.com/html_form_send.php" method="post" name="form1"> <strong>Your Details:</strong>Full name:
<input type="text" maxlength="50" name="fullname" size="30" />
E-mail Address:
<input type="text" maxlength="50" name="email_from" size="30" />Date of Visit:
<input type="text" maxlength="50" name="date" size="30" />
<strong>Accomodation:</strong>
<img class="size-medium wp-image-1382 alignnone" alt="val-du-charron-12+ (1)" src="http://www.bikesnwines.com/wp-content/uploads/2013/07/val-du-charron-12+-1- 300x125.jpg" width="400" height="170" />
<p style="text-align: left;"><strong><a title="Val Du Charron" href="http://vdcwines.com/" target="_blank">Val Du Charron Wine Estate</a></strong></p>
<p style="text-align: left;"><strong>Length of Stay:</strong>1 Night Stay only<strong></strong></p>
<p style="text-align: left;"><strong>Optional Extra's:</strong></p>
<p style="text-align: left;"><input type="checkbox" name="extra1" value="MTB" />Mountain Biking Tours<input type="checkbox" name="extra1" value="Spa" />Spa Treatements<input type="checkbox" name="extra1" value="Olive" />Olive Grove Tour and Tasting<input type="checkbox" name="extra1" value="Fishing" />Bass Fishing<input type="checkbox" name="extra1" value="HorseRide" />Horse Riding</p>
<strong>Cycling Levels:</strong>
<input type="radio" name="difficulty" value="Relaxed" />Relaxed
<input type="radio" name="difficulty" value="Moderate" />Moderate
<input type="radio" name="difficulty" value="Challenging" />Challenging
<strong>Transport:</strong>
<input type="radio" name="transport" value="Car Hire" />Car Hire
<input type="radio" name="transport" value="Transfers" />Airport or other Transfers
<input type="radio" name="transport" value="Self Drive" />Self Drive
Comments:
<textarea cols="25" maxlength="1000" name="comments" rows="6"></textarea>
<input type="submit" value="Enquire Now" />
</form>
and the php I am using
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "bookings#bikesnwines.com";
$email_subject = "Wellington Overnight Requests";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['fullname']) ||
isset($_POST['email_from']) ||
isset($_POST['date']) ||
isset($_POST['extra1']) ||
!isset($_POST['difficulty']) ||
!isset($_POST['transport']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$fullname = $_POST['fullname']; // required
$email_from = $_POST['email_from']; // required
$date = $_POST['date']; // required
$extra1 = $_POST['extra1']; // not required
$difficulty = $_POST['difficulty']; // required
$transport = $_POST['transport']; // required
$comments = $_POST['comments']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$fullname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Full Name: ".clean_string($fullname)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Date of Stay: ".clean_string($date)."\n";
$email_message .= "Optional Extra's: ".clean_string($extra1)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
//redirect to thank for registering page
header( 'Location: http://raceinterface.co.za/thank-you-for-registering/' ) ;
}
?>
when you submit it just opens a blank page..
I'm a bit blonde.. but super stuck..
Thanks
For a start, you do not have a field named simply 'email'. Try changing if(isset($_POST['email'])) { to if(isset($_POST['email_from'])) {
The name in the form for the input email is 'email_from', and in the php code, you have written 'if (!isset($_POST['email'])' . Is this a typo?
I don't see a variable email in your form.
So if you check in your php for $_POST['email'] it is never set.
You should build in an "else" after } in your .php.
Hi All i am trying to get my contacts page working i have input all the date but when i click on submit it just displays the php code on the next page. WHat am i doing wrong.
HTML Code:
<form method="post" name="contact" action="php\html_form_send.php">
<label for="name">Name:</label> <input type="text" id="name" name="name" class="required input_field" />
<div class="cleaner h10"></div>
<label for="email">Email:</label> <input type="text" id="email" name="email" class="validate-email required input_field" />
<div class="cleaner h10"></div>
<label for="telephone">Telephone:</label> <input type="number" name="telephone" id="telephone" class="input_field" />
<div class="cleaner h10"></div>
<label for="subject">Subject:</label> <input type="text" name="subject" id="subject" class="input_field" />
<div class="cleaner h10"></div>
<label for="text">Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
<div class="cleaner h10"></div>
<input type="submit" value="Send" id="submit" name="Submit" class="submit_btn float_l" />
<input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" />
</form>
PHP Code:
<body>
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "info#*********.com";
$email_subject = "website html form submissions";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['subject']) ||
!isset($_POST['text'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$subject = $_POST['subject']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$text = $_POST['text']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$subject)) {
$error_message .= 'The subject you entered does not appear to be valid.<br />';
}
if(strlen($text) < 2) {
$error_message .= 'The text you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($name)."\n";
$email_message .= "Last Name: ".clean_string($subject)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "text: ".clean_string($text)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- place your own success html below -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>
</body>
ERROR
"; echo $error."
"; echo "Please go back and fix these errors.
"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['subject']) || !isset($_POST['text'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $subject = $_POST['subject']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $text = $_POST['text']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid.
'; } if(!preg_match($string_exp,$subject)) { $error_message .= 'The subject you entered does not appear to be valid.
'; } if(strlen($text) < 2) { $error_message .= 'The text you entered do not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($name)."\n"; $email_message .= "Last Name: ".clean_string($subject)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "text: ".clean_string($text)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); #mail($email_to, $email_subject, $email_message, $headers); ?> Thank you for contacting us. We will be in touch with you very soon.
The PHP code is not beeing compiled. It's been served as a plain file. Check your PHP installation.
Hello,
I am wondering HOW I can have any and all errors (when the form is submitted) link to a general error page "Link an error.html". The php form I am using now, links to itself and is just an ugly page with no css formatting. Do I need the echos to link to an "error.html"?
I am working with the following HTML FORM :
<div id="contact">
<form name="contactform" method="post" action="send_form_email.php">
<label for="first_name">First <span class="red">*</span></label>
<input type="text" name="first_name" maxlength="50" size="30">
<label for="last_name">Last <span class="red">*</span></label>
<input type="text" name="last_name" maxlength="50" size="30">
<label for="email">Email <span class="red">*</span></label>
<input type="text" name="email" maxlength="80" size="30">
<label for="telephone">Telephone</label>
<input type="text" name="telephone" maxlength="30" size="30">
<label for="comments">Message <span class="red">*</span></label>
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
<input type="submit" value="Send Message">Email Form
</form>
</div>
This is the PHP File that I am Using :
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info#glustik.com";
$email_subject = "Project Quote Request";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- MY THANK YOU SUCCESS PAGE GOES HERE -->
<?php
}
?>
It is better to show the form validation errors along with the form. That way the user will get direct feedback.
You can use an array for all error messages.
<?php
$errors = array();
if(!isset($_POST['email'])) {
$errors['email'] = 'Email is required';
}
//similarly for other errors.
Now in the form
<input type="text" name="last_name" maxlength="50" size="30">
<label for="email">Email <span class="red">*</span></label>
<?= if(isset($errors['email'])) echo $errors['email'] ?>