Hi All,
I am trying to implement Ajax form validation but it doesnot seem to be working for my project. I however created a sample test project and set all the variables right and could make it work. I even debugged it using firebug and getting the responses right for the test project.
I have an error while i inspect it with chrome.
Error:
Uncaught TypeError: Object [object Object] has no method 'yiiactiveform'
Below is my code used to enable the form validation.
_form.php
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'op-form',
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
)
));
?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model, 'pin'); ?>
<?php echo $form->textField($model, 'pin', array('size' => 20, 'maxlength' => 20)); ?>
<?php echo $form->error($model, 'pin'); ?>
</div>
<?php $this->endWidget(); ?>
Controller:
public function actionCreate() {
$model = new Users;
$this->performAjaxValidation($model);
if (isset($_POST['Users'])) {
$model->attributes = $_POST['Users'];
if ($model->save())
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('create', array(
'model' => $model,
));
}
protected function performAjaxValidation($model) {
if (isset($_POST['ajax']) && $_POST['ajax'] === 'op-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
Any help would be much appreciated. Thanks