Ajax Form Problem

view/test/create.php


<?php

$this->breadcrumbs=array(

	'test',

);?>

<h2> Test Sample </h2>

<br>

<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

        'id'=>'subscription-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,'username'); ?>

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

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

        </div>


        <div class="row">

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

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

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

        </div>


        

        <div class="row buttons">

                <?php echo CHtml::submitButton( 'Save'); ?>

        </div>


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


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

controller/TestController.php


class TestController extends Controller

{

	public function actionIndex()

	{

		$this->render('index');

	}


	public function actionCreate()

	{

		$model=new test;

		$this->performAjaxValidation($model);

		if(isset($_POST['test']))

		{

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

			


			if($model->save())

			{

				//$this->redirect('index.php?r=test/create');

				

			}

		}

		$this->render('create',array('model'=>$model));

	}

	

	protected function performAjaxValidation($model)

	{

		if(isset($_POST['ajax']) && $_POST['ajax']==='subscription-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}

	}

	

	

}

models/test.php


class test extends CActiveRecord

{

	

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	

	public function tableName()

	{

		return 'tbl_test';

	}




	public function rules()

	{

		return array(

			array('username, password', 'required'),

			array('username, password', 'length', 'max'=>128),

			

			array('id, username, password', 'safe', 'on'=>'search'),

		);

	}


	

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'username' => 'Username',

			'password' => 'Password',

		);

	}


	

}

this ajax form not working , and how to create nice dialog message for this ajax form

thanks

help meeee pleaseeee

Try to check this out for the validation messages

http://www.yiiframework.com/extension/ajaxvalidationmessages/

About the form, try to look at firebug and see what’s going on behind the scene

Please share complete sample ajax form !

thanks

This is a working ajax form (no dialogs here, just real time validation

the $model is a topwebsites model that extends Yii’s AR




<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'top-websites-cr-form',

	'enableAjaxValidation'=>true,

	'clientOptions' => array(

      'validateOnSubmit'=>true,

      'validateOnChange'=>true,

      'validateOnType'=>false,

  	 ),

)); ?>


	<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,'domain'); ?>

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

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

	</div>


	<div class="row">

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

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

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

	</div>




	<div class="row buttons">

		<?php echo CHtml::submitButton('Submit'); ?>

	</div>


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


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