siabanie Posted July 11, 2011 Share Posted July 11, 2011 Hi all, I wonder if anyone could help me out; I have a PHP form that need to put a secure image to prevent spam. I have use this code provided in this page http://www.phpcaptcha.org/ - It works fine but the problem was when user entered an incorrect code it form still proceed which it not right. My form involved some PHP and Javascript to handle the error messages - I wonder if I need AJAX script for this as well? I use this Javascript to validate if the form has been enter blank or not: .. .. $('[name=captcha_code]').parent().removeClass('error'); if($('[name=captcha_code]').val()==""){ error_num++; error_mesg += "Please enter the image verification\n"; $('[name=captcha_code]').parent().addClass('error'); } .. .. And I need to put this code for matching code to verify if the code incorrect or correct. If incorrect a error message will display together. if ($securimage->check($_POST['captcha_code']) == false) { // the code was incorrect // you should handle the error so that the form processor doesn't continue // or you can use the following code if there is no validation or you do not know how echo "The security code entered was incorrect.<br /><br />"; //echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again."; //exit; } Can someone please assist me about this. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/241651-secure-image/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 11, 2011 Share Posted July 11, 2011 //exit; ^^^ You have commented out the exit; statement in the $securimage->check logic, so yes, the 'protected' code on the page will still be executed when the code does not match. Quote Link to comment https://forums.phpfreaks.com/topic/241651-secure-image/#findComment-1241254 Share on other sites More sharing options...
siabanie Posted July 11, 2011 Author Share Posted July 11, 2011 If I did not commented out the "exit" the page will display "The security code entered was incorrect" before I fill in the form. Quote Link to comment https://forums.phpfreaks.com/topic/241651-secure-image/#findComment-1241294 Share on other sites More sharing options...
PFMaBiSmAd Posted July 11, 2011 Share Posted July 11, 2011 The $securimage->check logic goes inside your form processing code. Quote Link to comment https://forums.phpfreaks.com/topic/241651-secure-image/#findComment-1241299 Share on other sites More sharing options...
siabanie Posted July 11, 2011 Author Share Posted July 11, 2011 You mean this code: if ($securimage->check($_POST['captcha_code']) == false) { echo "The security code entered was incorrect.<br /><br />"; exit; } should be inside HTML form? Quote Link to comment https://forums.phpfreaks.com/topic/241651-secure-image/#findComment-1241304 Share on other sites More sharing options...
siabanie Posted July 12, 2011 Author Share Posted July 12, 2011 Hello, does anyone can help me how I can validate CAPTCHA using AJAX? I have a form that check all the field error msges using jQuery but I don't know how I can do this using AJAX. <?php session_start(); require("include/application_top.php"); include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { echo "The security code entered was incorrect.<br /><br />"; //exit; //} ?> This snippets will displayed if field is empty $('[name=captcha_code]').parent().removeClass('error'); if($('[name=captcha_code]').val()==""){ error_num++; error_mesg += "Please enter the image verification\n"; $('[name=captcha_code]').parent().addClass('error'); } This snippets (not working) will displayed if code entered is not match the code...but I think I need to add AJAX script somewhere which I need help. $('[name=captcha_code]').parent().removeClass('error'); if ($securimage->check($_POST['captcha_code']) == false){ error_num++; error_mesg += " The security code entered was incorrect \n"; $('[name=captcha_code]').parent().addClass('error'); } Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/241651-secure-image/#findComment-1241741 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.