JamesB Posted December 21, 2014 Share Posted December 21, 2014 Hey I have a recaptcha on a site I'm making for a friend. If I enter the correct words first time, it works. If I enter incorrect words first time, then press reload via the captcha button, then enter correct words, it works. But if I enter incorrect words first time, then enter correct words after, it won't work. Any idea why this is? $privatekey = "my 40 byte private key is here";$resp = recaptcha_check_answer( $privatekey, $_SERVER["REMOTE_ADDR"], $this->input->post("recaptcha_challenge_field"), $this->input->post("recaptcha_response_field")); Link to comment Share on other sites More sharing options...
JamesB Posted December 22, 2014 Author Share Posted December 22, 2014 So thanks to this link I now realize the captcha needs to be reloaded for a second attempt. http://stackoverflow.com/questions/21768129/recaptcha-always-failing-on-the-second-time I'm using AJAX for my form, so I've decided to create the script tag in JS and append it to the element upon ajax response, but it's not working. Here's my code: $('#register_form').ajaxForm({ url: base_url+'member/register', type: 'post', success: function(responseText, statusText, xhr, form){ $('#register_ajax_container').hide(0); $('#register_form_errors').html(responseText); $('.form_errors').show(); // reload the captcha $.get(base_url+'member/register_new_captcha', '', function(data){ // this URL retrieves the public key for the captcha var script=document.createElement('script'); script.type='text/javascript'; script.src='http://www.google.com/recaptcha/api/challenge?k='+data; $('#register_captcha_container').html(''); // clear existing captcha (<script> and <noscript>) $('#register_captcha_container').append(script); // add new captcha (<script>) todo: <noscript> too //$('#register_captcha_container').html(data); }); }}); I'm simply not seeing the captcha after a register attempt. Link: http://www.ukscifi.net/uks2/ If you click on Register at top right, then click Register at bottom, the captcha will disappear but not reappear. Link to comment Share on other sites More sharing options...
JamesB Posted December 22, 2014 Author Share Posted December 22, 2014 (edited) Fixed it. All I needed was Recaptcha.reload(); $('#register_form').ajaxForm({url: base_url+'member/register',type: 'post',success: function(responseText, statusText, xhr, form){$('#register_ajax_container').hide(0);$('#register_form_errors').html(responseText);$('.form_errors').show();Recaptcha.reload();}}); Edited December 22, 2014 by JamesB Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now