Elgg 2.3.9
Captcha plugin https://elgg.org/plugins/914006 of @iionly
I'd like to add a refresh button to the page that will refresh only the captcha (not the page).
The following code is from captcha/views/default/input/captcha.php
I added a refresh icon - please see my addition between the comment lines.
My question is what is the code I need to attach to the icon in order to refresh the captcha.
Thank yo very much.
$token = captcha_generate_token();
echo '<div class="captcha">';
echo elgg_view_field([
'#type' => 'hidden',
'name' => 'captcha_token',
'value' => $token,
]);
echo '<div class="captcha-right">';
echo elgg_view('output/img', [
'src' => "captcha/$token",
'alt' => "captcha_image",
'class' => 'captcha-input-image',
]);
//---- my addition ------
echo '<span id="refresh" class="elgg-icon fa elgg-icon-refresh fa-refresh"></span>';
//-----------------------
echo '</div>';
echo '<div class="captcha-left">';
echo elgg_view_field([
'#type' => 'text',
'#label' => elgg_echo('captcha:entercaptcha'),
'name' => 'captcha_input',
'class' => 'captcha-input-text',
'required' => true,
]);
echo '</div>';
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Reuven@reuven
Reuven - 0 likes
- iionly@iionly
iionly - 0 likes
- Reuven@reuven
Reuven - 0 likes
You must log in to post replies.Maybe a better question is what is the url to call with AJAX ?
I don't have a solution at hand. I also have currently no time trying to come up with a solution. Sorry.
As the Captcha plugin uses no ajax so far, there's no view you could simply call via ajax to get it working. The captcha input view generates the security token on page loading (also used for generating the token image then and necessary later on validating the user input). If you want to refresh the captcha image only, you would also have to deal with refreshing the security token. Without JS code that won't work for sure. Even then I'm not sure if it will work at all (as the token has to be created on the server). But I can't provide much useful info without trying myself and that's not possible right now due to lack of time.
Thank you @iionly