Hi,
I want to have 2 forms on 1 page, I had duplicated the 1st form and gave it an other ID but for some reason the 2nd forms validation / success messages do not appear in the form page but a blank page. The form is send successfully however.
<!--
<form id="contactform2" action="contact_form2.php" method="post"><br>
<div class="col-md-6">
<div class="row">
<div class="col-sm-12">
<div class="form-group wow fadeInUp" data-wow-delay="0.2s">
<label class="sr-only">Your Name</label>
<input type="text" id="name2" name="name2" class="form-control" placeholder="Your Name">
</div>
</div>
<div class="col-sm-12">
<div class="form-group wow fadeInUp" data-wow-delay="0.4s">
<label class="sr-only">Your Email</label>
<input type="email" id="email2" name="email2" class="form-control" placeholder="Your Email">
</div>
</div>
<div class="col-sm-12 ">
<div class="form-group wow fadeInUp" data-wow-delay="0.8s">
<label class="sr-only">Massage</label>
<textarea class="form-control textarea" id="message2" name="message2" rows="5" placeholder="Massage"></textarea>
</div>
</div>
<div class="col-sm-12">
<div class="form-group wow fadeInUp" data-wow-delay="1s">
<button type="submit" id="send2" class="btn btn-default ">Send Massage</button>
<a id="about" href="contact_form2.php" title="summary">blblblb</a>
</div>
</div>
</div class="row">
</div class="col-md-6">
</form>
<div id="response"></div>
<!--
And the php script:
<?php
foreach($_POST as $key => $value) {
if(ini_get('magic_quotes_gpc'))
$_POST[$key] = stripslashes($_POST[$key]);
$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$errors = array();
if(strlen($name) < 2) {
if(!$name) {
$errors[] = "You must enter a name.";
} else {
$errors[] = "Name must be at least 2 characters.";
}
}
if(!$email) {
$errors[] = "You must enter an email.";
} else if(!validEmail($email)) {
$errors[] = "You must enter a valid email.";
}
if(strlen($message) < 10) {
if(!$message) {
$errors[] = "You must enter a message.";
} else {
$errors[] = "Message must be at least 10 characters.";
}
}
if($errors) {
$errortext = "";
foreach($errors as $error) {
$errortext .= "<li>".$error."</li>";
}
die("<span class='failure'>The following errors occured:<ul>". $errortext ."</ul></span>");
}
$to = "Lexi@gmail.com";
$subject = "Contact Form: $name";
$message = "$message";
$headers = "From: $email";
mail($to, $subject, $message, $headers);
die("<span class='success'>Success! Your message has been sent.</span>");
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
$isValid = false;
}
else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
str_replace("\\\\","",$local)))
{
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
{
$isValid = false;
}
}
return $isValid;
}
?>
What I have tried:
I have tried to change all the field names and ID's in the second form (name2, email2)
I have tried to copy the php script end name it contact_form2.php and pointed the 2nd form to it.