CCaptcha doesn't render refresh link

I have a problem with the refresh link in my form.

I use the captcha in my contact form and there it works fine.

In annother form it don’t render the refresh link. The view code for the captcha is the same as in the contact form.




<?php if(CCaptcha::checkRequirements()): ?>

	<div class="row captcha">

		<?php //echo $form->labelEx($model,'verifyCode'); ?>

		<div>

		<?php $this->Widget('CCaptcha'); ?>

		<?php echo $form->textField($model,'verifyCode'); ?>

		</div>

		<div class="hint"><?php echo yiiparam('captchaHint'); ?></div>

		<?php echo $form->error($model,'verifyCode'); ?>

	</div>

<?php endif; ?>



This form is shown in a juiDialog. I think that must be the problem.

This is the js code in the view call the form:




//this function is called from the link or button

	function showAdRequestForm() {

	  $.ajax({

      url: base_url+'/ad/adrequest',

      data: $(this).serialize()+'&requestType=adrequest&adId='+ <?php echo $model->id;?>,

      type:'post',

      dataType:'json',

      success:adRequestSuccess

	 });

	 $('#dialogAdRequest').dialog('open');

    return false; 

	}



This is my controller action code:




 /**

	 * Send an email to the advertiser or a violation email to the webmaster.

	 */

	public function actionAdRequest(){

	  $model=new AdRequestForm();

	  $model->requestType=$_POST['requestType'];

    if(isset($_POST['AdRequestForm'])) {

      $model->attributes=$_POST['AdRequestForm'];

      

      if($model->validate()) {

        $msg_error='Ihre Anfrage konnte nicht weitergeleitet werden';

        $msg_success=$model->requestType=='adrequest'?'Ihre Anfrage wurde an den Anbieter weitergeleitet': 'Ihr Anliegen wurde an den webmaster von'. Yii::app()->name. ' weitergeleitet.';

                //We send the email to the advertiser

        if($model->sendRequest($_POST['adId'])){

          $msg=$msg_success;

        }

        else {

          $msg=$msg_error;

        }  

        echo CJSON::encode(array(

          'status'=>'success', 

          'div'=>$msg

         ));

        exit;

      }

    }

    $div=$this->renderPartial('_form_dialog_request', array('model'=>$model), true);

    echo CJSON::encode(array(

        'status'=>'failure', 

        'div'=>$div));

    exit;  

  }



What is your problem? What do you expect to happen and what actually happens? Didn’t get your problem…

The refresh link "Generate new image" is not rendered in the dialog form, in the contact form it is rendered.

The button is added by javascript as you can see in the code here:

https://github.com/yiisoft/yii/blob/master/framework/web/widgets/captcha/CCaptcha.php#L128

Make sure your javascript is added to html output, runs without errors and that the id used be CCaptcha is unique.

The problem was that a second jquery script was registered.

I use now the renderBegin() and renderEnd() functions to render my form and then it works.

Annother possibility is the NLSClientScript extension to prevent more then one registration of jquery.