CaptchaBundle icon indicating copy to clipboard operation
CaptchaBundle copied to clipboard

Renew_captcha button doesn't change the image

Open adamkotecki opened this issue 7 years ago • 1 comments

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.

adamkotecki avatar Jan 26 '18 14:01 adamkotecki

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.

MaximePinto avatar Nov 30 '21 11:11 MaximePinto