integrate form validation and captcha helper - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: integrate form validation and captcha helper (/showthread.php?tid=48481) |
integrate form validation and captcha helper - El Forum - 01-18-2012 [eluser]Unknown[/eluser] application/libraries/MY_Form_validation.php Code: <?php in controller Code: class Welcome extends CI_Controller { Code: <?php echo $captcha?> integrate form validation and captcha helper - El Forum - 06-25-2014 [eluser]B3geN14S[/eluser] Hi, I'm facing a problem with captcha validation. I followed the example provided above. I managed to visualise captcha on pages and to set expiration..., but no matter what I write in the input field, script proceeds to validation, no matter if what I entered matches the image text or not. I aslo got this error: A PHP Error was encountered Severity: Notice Message: Undefined index: captcha Filename: libraries/MY_Form_validation.php Line Number: 17 The content of MY_Form_validation.php, I'll post below. I'm sure it's a ridiculous problem... Any help is appreciated. Here's my code: regform.php Code: <label for="captcha">Antispam check<span >*</span></label> form.php (Controller) Code: class Form extends CI_Controller { MY_Form_validation.php Code: class MY_Form_validation extends CI_Form_validation Thanks in advance! integrate form validation and captcha helper - El Forum - 06-25-2014 [eluser]treenef[/eluser] What I do is generate a random four digit number using the random library. Then in the controller I set this in a session. When the form is submitted I check the session matches the input text. Code: $random = "2839"; <- store this in a session integrate form validation and captcha helper - El Forum - 06-25-2014 [eluser]CroNiX[/eluser] According to your error message, $_POST['captcha'] doesn't exist on this line: Code: $binds = array($_POST['captcha'], $this->CI->input->ip_address(), $expiration); Are you sure the field is named "captcha" in your form? It looks like you have 2 errors on this line as well: Code: $this->set_message('captcha_err', The %s field must content a valid captcha code.'); The error message name (first parameter) needs to be the same name as the form validation rule. So 'captha_err' should just be 'captcha'. You are also missing a single quote from the beginning of the 2nd parameter. integrate form validation and captcha helper - El Forum - 06-25-2014 [eluser]B3geN14S[/eluser] Thanks for you comment CroNiX, Missing single quote is a stupid mistake of mine. I think it is correct in the original code. I must have omitted it when pasting the code here. I'll try also with the first parameter corrected. And Yes! I'm sure the text input field is named "captcha" as in this portion of code: Code: <label for="captcha">Antispam check<span >*</span></label> Otherwise, I suppose the problem must reside in the logic (the Controller). Code: if ($this->form_validation->run() == FALSE) If I call Code: $this->form_validation->captcha(); I'll report back tomorrow. integrate form validation and captcha helper - El Forum - 06-25-2014 [eluser]B3geN14S[/eluser] [quote author="treenef" date="1403702768"]What I do is generate a random four digit number using the random library. Then in the controller I set this in a session. When the form is submitted I check the session matches the input text. Code: $random = "2839"; <- store this in a session Thanks for the option you proposed, treenef! Since this is my first project with CodeIgniter, could you provide some sample code to make it clearer to me? integrate form validation and captcha helper - El Forum - 06-25-2014 [eluser]treenef[/eluser] I'll post an example tomorrow. integrate form validation and captcha helper - El Forum - 06-25-2014 [eluser]B3geN14S[/eluser] UPDATE Hi, guys! Just an update to my problem. It seems that after correcting the parameters CroNiX suggested, I succeded to make everything work fine! What I also did, was to remove the call to this in the controller: Code: $this->form_validation->captcha(); That was the reason to the Undefined index: captcha error. I didn't have to call the this function again in the controller... Ooops! Sorry for bothering you, guys, and once more, thank you very much for your help! P.S. Now my boss won't torture me like hell |