Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
39
rated 0 times [  43] [ 4]  / answers: 1 / hits: 16847  / 13 Years ago, sun, may 29, 2011, 12:00:00

I want to force my site to refresh the captcha image everytime it loads, so I have a javascript method triggered with the onload() event. Here I have the following line:



document.getElementById('yw0_button').click;


Firebug doesn't detect any errors, and for testing purposes I have added an alert right after the displayed line, and the alert pops up each time the page is loaded. However, the image doesn't refresh!



This is what I believe is relevant about the view file:



<?php if(extension_loaded('gd')): ?>
<div class=row>
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php
$this->widget('CCaptcha',
array('showRefreshButton'=>true,
'buttonType'=>'button',
'buttonOptions'=>
array('type'=>'image',
'src'=>/path/images/refresh-icon.png,
'width'=>30,
),
'buttonLabel'=>'Refrescar imagen'),
false);
?>
<br>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class=hint>
Porfavor ingrese las letras como las ve en la imagen superior.
<br/>No hay distincion entre minúsculas y mayúsculas.</div>
</div>
<?php endif; ?>


Any ideas?






@k to the z just saw this! Yes sure, if you could help me find a more proper solution it would be awesome! This is what i believe is relevant about the view file:



<?php if(extension_loaded('gd')): ?>
<div class=row>
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php
$this->widget('CCaptcha',
array('showRefreshButton'=>true,
'buttonType'=>'button',
'buttonOptions'=>
array('type'=>'image',
'src'=>/path/images/refresh-icon.png,
'width'=>30,
),
'buttonLabel'=>'Refrescar imagen'),
false);
?>
<br>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class=hint>
Porfavor ingrese las letras como las ve en la imagen superior.
<br/>No hay distincion entre minúsculas y mayúsculas.</div>
</div>
<?php endif; ?>


In the controller I grant authorized users permission in the accessRules() method to the captcha action, and thats about all. Is there something else I could post?


More From » frameworks

 Answers
25

In case anyone goes through a similar problem whilst getting started with Yii.. This is how I resolved the CAPTCHA issue triggering a click: I have an event triggered the the onload event, which has the following code:



$('#yw0_button').click();



There surely must be a better way, im open to suggestions! However as a temporary solution this works just fine, refreshing the captcha image each time the page is loaded. Good luck!



EDIT: What I did was handle the onload event for my html page like this



<body onload=initialize()> 
..
</body>


Then in my js file:



function initialize() 
{
$('#yw0_button').click();
}

[#91990] Friday, May 27, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
estefanib

Total Points: 508
Total Questions: 104
Total Answers: 83

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;