Basically I have this form that needs all the information in before it can be submitted.
now i have tested it and it works in safari and firefox. If i dont enter a phone number it puts a red box round the text box and doesnt submit. If I put in one digit I get a error saying it needs 11 digits.
Now every so often an email comes through from this form with out a phone number been entered.
How??
Form part
contact_form.php
Virtual cookie or beer for anyone that can help.
now i have tested it and it works in safari and firefox. If i dont enter a phone number it puts a red box round the text box and doesnt submit. If I put in one digit I get a error saying it needs 11 digits.
Now every so often an email comes through from this form with out a phone number been entered.
How??
Form part
PHP:
<div id="contact_form">
<form action="contact_form.php" id="validate_form" method="post" class="showtextback">
<ul>
<li><label for="name">Your Name: (*)</label><input id="name" type="text" name="name" value="" class="required" /> </li>
<li><label for="phone">Your Phone number: (*)</label><input id="phone" type="text" name="phone" value="" class="required" /> </li>
<li><label for="email">Your Email: (*)</label><input id="email" type="text" name="email" value="" class="required" /> </li>
<li><label for="message">Your message: (*)</label><textarea id="message" name="message" rows="8" cols="40" class="required"></textarea></li>
<li><input type="submit" value="Send" /><span class="loading"></span></li>
</ul>
</form>
</div>
<!-- /contact form -->
contact_form.php
PHP:
<?php
// edit these lines
$your_name="My Name";
$your_email="MyEmail";
$your_web_site_name="Mywebsite";
?>
<?php
//If the form is submitted
if(isset($_POST['name'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['name']) === '') {
$hasError = true;
} else {
$name = trim($_POST['name']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) === '') {
$hasError = true;
} else if (!preg_match('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$^', trim($_POST['email']))) {
$hasError = true;
$errorMessage = "Please enter a valid email address!";
} else {
$email = trim($_POST['email']);
}
//phone
if (trim($_POST['phone'] === ''))
{
$hasError = true;
}
else if (!preg_match('(\d{11})', trim($_POST['phone'])))
{
$haserror = true;
$errorMessage = "Your phone number must have 11 digits";
}
else
{
$phone = trim($_POST['phone']);
}
//company name
if(isset($_POST['company_name'])) $company_name = trim($_POST['company_name']);
//company url
if(isset($_POST['company_url'])) $company_url = trim($_POST['company_url']);
//Check to make sure comments were entered
if(trim($_POST['message']) === '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = $your_email;
$subject = 'Contact Form Submission from '.$name;
//message body
$body ="Name: $name \n\n";
$body .="Email: $email \n\n";
$body .="Phone: $phone\n\n";
if(isset($company_name)) $body .="Company Name:$company_name\n\n";
if(isset($company_url)) $body .="Company Url:$company_url \n\n";
$body .="Message: $comments";
$headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
<?php if(isset($emailSent) == true) { ?>
<div class="ok_box">
<h3>Thanks, <?php echo $name;?></h3>
<p>Your email was successfully sent. We will be in touch soon.</p>
</div>
<?php } ?>
<?php if(isset($hasError) ) { ?>
<div class="error_box">
There was an error submitting the form.
<br />
<?php echo $errorMessage;?>
</div>
<?php } ?>
Virtual cookie or beer for anyone that can help.