Hi,
I’m hoping to get some help with some PHP code I’m having trouble with on my contact form page…
Please see the below quoted text from a conversation I’ve just had with someone in the Javacsript forum who helped with fixing the Javascript validation for my contact form, to see the PHP problem I need help with, thanks.
Exactly, just copy and paste this:
Code JavaScript:
function validateForm(){
var errorMessage=“”;
var name=document.forms[“contact”][“txtName”].value;
var email=document.forms[“contact”][“txtEmail”].value;
var input=document.forms[“contact”][“txtInput”].value;
var atpos=email.indexOf(“@”);
var dotpos=email.lastIndexOf(“.”);
if (name==null || name==“”){
errorMessage = "Your Name is required.
";
}
if (email==null || email==“”){
errorMessage += "Email address is required.
";
} else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length){
errorMessage += "Please enter a valid email address.
";
}
if (input==null || input==“”){
errorMessage += "Captcha code is required.
";
}
if (errorMessage !=“”){
alert(errorMessage);
return false;
}
}
Excellent, that worked, thanks very much.
One other thing remains to fix, the catchpa code submits even if the wrong code is submitted, I have copy and pasted the following PHP code form the original page on which I have the catchpa code into the contact page head section , but it’s not working, any chance you would be able to help with this, or is it better to post this in another section of the forums?
PHP
Code:
<?php
if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['txtInput']) != 0)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "The captcha code does not match";
}
?>
If more information is needed, my original post in the Javascript forum, which notes more code, is here: http://www.sitepoint.com/forums/showthread.php?925501-form-validation-not-working