ojengwa / django-simple-captcha

Automatically exported from code.google.com/p/django-simple-captcha
MIT License
1 stars 0 forks source link

Add refresh button near input field in a form #46

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Sometimes captcha is not readable by human and it's needed refresh button to 
renew captcha by AJAX.

Original issue reported on code.google.com by a.vostrjakov on 27 Mar 2011 at 4:32

GoogleCodeExporter commented 9 years ago
This would be nice but would have to rely on AJAX (we can't reload the whole 
form). This could prove difficult because it'd have to integrate with whatever 
javascript framework the site is using (if any)

Patches more than welcome, though.

Original comment by mbonetti on 27 Mar 2011 at 8:08

GoogleCodeExporter commented 9 years ago
As result I suggest this patch without javascript+ajax part. This patch allow 
to get a new key by ajax. After it, of course, it's needed to refresh elements 
on a form but I don't know how make it universally.

In my case i wrote (using jquery and jinja2 templates):

<script type="text/javascript">
$(document).ready(function() {
    $('#captcha_refresh').click(function() {
        $.get("{{ url('captcha-new-key') }}", function(data) {
            var image_url = "{{ url('captcha-image', 0) }}"
            image_url = image_url.replace('/0', '/' + data);
            $('#id_captcha_image').attr('src', image_url);
            $('#id_captcha_0').val(data);
            $('#id_captcha_1').val('');
        });
    });
});
</script>

So, I suggest to add this patch. The rest of the work developer can implement 
yourself.

Original comment by a.vostrjakov on 28 Mar 2011 at 10:06

Attachments:

GoogleCodeExporter commented 9 years ago
I do as you say, why appera as follows error:

Could not parse the remainder: '('captcha-new-key')' from 
'url('captcha-new-key')'

thanks!

Original comment by jzz.game...@gmail.com on 9 May 2012 at 1:47

Attachments:

GoogleCodeExporter commented 9 years ago
love you and thank you!

Original comment by Age...@gmail.com on 4 Jul 2013 at 2:13