I have a modal dialog in which I’m making form submission via Ajax
First time it successfully loads recaptcha.
But if there is validation error and it reloads content again, captcha doesn’t show! There is empty space instead of captcha.
Please suggest where I’m wrong.
In main view I have
<div id="modaladd-content">
<?php $this->renderPartial('partials/addsiteform3', array('model'=>$model)); ?>
</div>
partials/addsiteform3.php :
<?php
//Yii::app()->getClientScript()->registerScriptFile('/js/addsite-ajax.js');
$form = $this->beginWidget('CActiveForm', array(
'id' => 'addwebsite-form',
'action' => array('site/addsite'),
'enableAjaxValidation' => false,
));
?>
<div class="row">
<?php echo $form->labelEx($model, 'dName'); ?>
<?php echo $form->textField($model, 'dName', array('size' => 20, 'maxlength' => 128)); ?>
<?php echo $form->error($model, 'dName'); ?>
</div>
<?php
Yii::import('ext.recaptch.reCAPTCHA.*');
require_once('recaptchalib.php');
$publickey = "xxx"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
<?php
echo CHtml::ajaxButton("Submiiit", CController::createUrl('site/addsite'), array(
'type'=>'POST',
'update' => '#addwebsite-form'));
?>
<?php $this->endWidget(); ?>
in Controller:
public function actionAddsite() {
if (isset($_POST['AddSiteForm'])) {
$model = new AddSiteForm();
$model->attributes = $_POST['AddSiteForm'];
if ($model->validate()) {
echo 'Success!';
}
else {
$this->renderPartial('partials/addsiteform3', array('model' => $model), false, true) ;
}