Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renew_captcha button doesn't change the image #183

Open
adamkotecki opened this issue Jan 26, 2018 · 1 comment
Open

Renew_captcha button doesn't change the image #183

adamkotecki opened this issue Jan 26, 2018 · 1 comment

Comments

@adamkotecki
Copy link

I'd like renew_captcha button to chanege code&image to new one. But it just renews the same image as we can see on generated Javascript code:

<script type="text/javascript"> function reload_captcha_5a6b33132e1ff() { var img = document.getElementById('captcha_5a6b33132e1ff'); img.src = '/captcha/c587a12bc2c53733177b8cbc2f684752.jpg?n=' + (new Date()).getTime(); } </script>

Is there a feature that one can change displayed captcha image&code without reloading the page?

I am using Symfrony 3.4

PHP code:
$builder->add ( 'captcha', CaptchaType::class, [ 'attr' => [ 'class' => 'form-control' ], 'reload' => true, 'as_url' => true, 'as_file' => true ] );

TWIG: source
<img class="captcha_image" id="{{ image_id }}" src="{{ captcha_code }}" alt="" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" /> {% if reload %} <script type="text/javascript"> function reload_{{ image_id }}() { var img = document.getElementById('{{ image_id }}'); img.src = '{{ captcha_code }}?n=' + (new Date()).getTime(); } </script> <a class="captcha_reload" href="javascript:reload_{{ image_id }}();">{{ 'Renew'|trans({}, 'gregwar_captcha') }}</a> {% endif %}

Browser doesn't show any erros. Network shows request that the same image is being donloaded again.

@MaximePinto
Copy link

hello, I know the tipic is old, but maybe it will help some.

After putting:
as_url: true
reload: true
the form rendering and its script for the renew button
routing in routing.yml

Do not forget to authorize the route in your acess_control (security.yml) for the url to call images

  • {path: ^ / generate-captcha /, roles: IS_AUTHENTICATED_ANONYMOUSLY}

that's what was blocking me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants