Yii Framework Forum: [solved] Ajax Validation not working (CActiveForm) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[solved] Ajax Validation not working (CActiveForm) Rate Topic: -----

#1 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 16 September 2010 - 09:56 AM

Yii 1.1.3
Webapp created using yiic tool

I am testing using the generated Contact Form.

/site/contact.php:

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'contact-form',
    'enableAjaxValidation'=>true,
)); ?>

[form fields]

<?php $this->endWidget(); ?>

</div><!-- form -->


SiteController.php:

public function actionContact()
{
	$model=new ContactForm;
		
	// Uncomment the following line if AJAX validation is needed
	$this->performAjaxValidation($model);
		
	if(isset($_POST['ContactForm']))
	{
		$model->attributes=$_POST['ContactForm'];
			
		if($model->validate())
		{
			...
		}
		
		$this->render('contact', array('model'=>$model));
	}
	
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='contact-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
}


I have not modified ContactForm model. Normal validation is working fine.
0

#2 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 16 September 2010 - 12:18 PM

jquery.js is included but yiiactiveform.js is not being included for some reason. I have not disabled it anywhere.

EDIT: I got my answer - I had removed $form->error() from my input fields.
0

#3 User is offline   Liming 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 19-July 10

Posted 03 January 2011 - 10:49 PM

View PostGSTAR, on 16 September 2010 - 12:18 PM, said:

jquery.js is included but yiiactiveform.js is not being included for some reason. I have not disabled it anywhere.

EDIT: I got my answer - I had removed $form->error() from my input fields.

Thank you.I have spend a lot of time to resolve it;
0

#4 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 04 January 2011 - 03:35 AM

View PostGSTAR, on 16 September 2010 - 12:18 PM, said:

EDIT: I got my answer - I had removed $form->error() from my input fields.

The easiest errors are always hardest to find! :] Glad, you found it after all.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#5 User is offline   efcoders 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 09-February 12

Posted 22 April 2013 - 07:10 AM

This should be somewhere explain in very clear manners how this AJAX VALIDATION WORKS...
Especially $form->error() Hint...

Thanks
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users