Cathpa validation problem


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 !=“”){
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?


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:

Hi there,

Where do you have the captcha code from?
Is it something you wrote yourself or is it a script you have from somewhere?

I copy and pasted the catchpa code into the contact form from another page on my site (, which a programmer coded for me.

Ah, ok.
Is it important to you to have the same style of captcha image on your new page, or would you be fine with using another captcha script from somewhere else?

Any catchpa code is fine.

Ok, well basically you have two options.

[]You could use one of the many Captcha services out there. They are free and easy to set up. Recaptcha is probably the most well known:, or you could just peruse this list:
]I just dug a simple Captcha script out of my snippets archive. I could let you have this if you like and help you integrate it into your page. So that you can see what the end product is like, I’ve made a quick demo page here:
[/LIST]Please bear in mind however, that these Captchas present some people with quite a usability barrier (my parents for example have real trouble filling them out), so if I was you, I would opt for a service like Recaptcha (which at least gives you the possibility of listening to what is being displayed).


Edit: Of course we could also try and re-implement your current Captcha system on your new page. For this to work you would have to provide the code which is used to generate the image, the code used to include the generated image in your form and also the code to evaluate whether or not the correct code was entered.

I will have a look at recaptcha and I will probably integrate that into my contact form. Thanks very much for your help.