mewebstudio / captcha

Captcha for Laravel 5/6/7/8/9/10/11
MIT License
2.45k stars 453 forks source link

How to refresh captcha image #54

Closed pishguy closed 9 years ago

pishguy commented 9 years ago

i'm using this bundle in laravel 4, but i can not refresh captcha image by click on refresh icon

followtheart commented 9 years ago

Using jquery or zepto.js to bind click event .

pishguy commented 9 years ago

yes i know that, but i can not change that. i dont know how to change, please help me to use this useful package. thanks

followtheart commented 9 years ago
$('#captcha').click(function(){
    $('#captcha').attr('src','/captcha/default?'+Math.random());
    });
pishguy commented 9 years ago

Thanks. after click on captcha, thats set to hide and don't work correctly

pishguy commented 9 years ago

​Thanks sir. after click on CAPTCHA, image hide and dont refresh, thanks to reply

mewebstudio commented 9 years ago

jQuery AJAX example for Captcha:

routes.php

Route::get('/get_captcha/{config?}', function (\Mews\Captcha\Captcha $captcha, $config = 'default') {
    return $captcha->src($config);
});

view_file.blade.php

<img src="{{ captcha_src() }}" alt="captcha" class="captcha-img" data-refresh-config="default">

application.js

$('img.captcha-img').on('click', function () {
    var captcha = $(this);
    var config = captcha.data('refresh-config');
    $.ajax({
        method: 'GET',
        url: '/get_captcha/' + config,
    }).done(function (response) {
        captcha.prop('src', response);
    });
});

Captcha image click to refresh.

CN201 commented 7 years ago

I try to do that but it's not working sorry about my enlish

keepchen commented 7 years ago
<img src="{{captcha_src()}}" onclick="this.src='/captcha/default?'+Math.random()" id="captchaCode" alt="" class="captcha">
<a rel="nofollow" href="javascript:;" onclick="document.getElementById('captchaCode').src='captcha/default?'+Math.random()" class="refresh">refresh</a>

Hope to be helpful.

CN201 commented 7 years ago

Thank you so much for reply It works ^ ^

CN201 commented 7 years ago

Sorry to ask again, how to do multiple recaptcha on same page

keepchen commented 7 years ago

@CN201 See https://github.com/mewebstudio/captcha/issues/56

CN201 commented 7 years ago

thank you KeepChen

francistito commented 5 years ago

Thank you @keepchen

abdulrojab commented 2 years ago

@keepchen After searching in many discussions and tutorials, this method is great. Thank you, sir!