CodeIgniter Forums
reCAPTCHA not showing after an ajax call - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: reCAPTCHA not showing after an ajax call (/showthread.php?tid=45987)



reCAPTCHA not showing after an ajax call - El Forum - 10-13-2011

[eluser]Unknown[/eluser]
Hello,
I'm trying to insert a reCAPTCHA code into my login form and everything went pretty well.

But since the form is sent trough an ajax $.(post) command, if the form_validation->run() fails the page is reloaded.

if the form is reloaded, it seems that reCAPTCHA can't be reloaded into the form and I can't figure out why.

here is the view code:

Code:
[removed][removed]
[removed]
    
    $(function() {
            $( "#submit" ).button();
    });
    
    function showRecaptcha(element) {
           Recaptcha.create("6LcjCMYSAAAAAB7KIMKe3m4JyWse3xS8p74Ri50O", element, {
             theme: "red",
             callback: Recaptcha.focus_response_field});
         }
    
    $(document).ready(function(){
        showRecaptcha('recaptcha_div');
        $("#loading").hide();
        $("#loginform").submit(function(e)
        {
            e.preventDefault();
            $("#loading").slideDown('fast');
            $("#formcontainer").slideUp();
            $.post("<?=base_url();?>aziende/login", $("#loginform").serialize(),function(data){
                $("#formcontainer").html(data).slideDown('slow');
                $("#loading").hide();
            });
            
        })
    });
[removed]
<?php if(!$submitted) { ?>
<div id="loading" align="center"><img src="&lt;?=base_url();?&gt;images/loading.gif" /></div>
<div id="formcontainer">
    &lt;?php } ?&gt;
    <div align="center" id="formError">&lt;?php echo validation_errors(); ?&gt;</div><br />
&lt;form method="post" action="" id="loginform"&gt;
<table border="0" width="100%">
        <tr><td align="right" width="50%">
    <label for="email">Email:</label></td>
        <td align="left">&lt;input type="text" name="email" placeholder="Il tuo indirizzo email" value="&lt;?=$email;?&gt;" /&gt;&lt;/td>
            </tr>
        <tr><td align="right">
    <label for="password">Password:</label></td>
        <td align="left">&lt;input type="password" name="password" value="&lt;?=$password;?&gt;" /&gt;&lt;br />
</td></tr>
    <tr><td colspan="2" align="center"><div id="recaptcha_div"></div></td></tr>
    <tr><td colspan="2" align="center">&lt;input type="hidden" name="go" value="1" /&gt;&lt;br />
      &lt;input type="submit" value="Registrati!" id="submit" /&gt;&lt;/td>
    </tr>
</table>
&lt;/form&gt;
&lt;?php if(!$submitted) { ?&gt;</div>&lt;?php } ?&gt;

I tried loading reCAPTCHA without the javascript command (trough iframe) but the problem seems to persist.

this is the view that is reloaded with ajax on form error.

when I say that reCAPTCHA is not reloaded I mean that the whole reCAPTCHA box is not showing up...

ty for help Smile

P.S.
- sometimes it works without any code change...
- if I submit the right word the login is successfull, so there is no controller error on form_validation
- the first "removed" items on my code are the script for google reCAPTCHA api