Yii Forms should make my life easy?

A normal form works, but I like ajax forms.

I added this code

<div class="form">

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




	'clientOptions'=> array('validateOnSubmit'=>true),



	<?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 class="row">

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

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

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


	<div class="row rememberMe">

		<?php echo $form->checkBox($model,'rememberMe'); ?>

		<?php echo $form->label($model,'rememberMe'); ?>

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


	<div class="row submit">


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


			echo CHtml::ajaxSubmitButton('Login2', 'site/login');



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

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

in the controller



			echo CActiveForm::validate($model);



When i push login2 I see from firebug that I get in response

{"LoginForm_username":["\u041b\u043e\u0433\u0438\u043d: cannot be blank."],"LoginForm_password":["\u041f\u0430\u0440\u043e\u043b\u044c: cannot be blank.","Incorrect username or password."]}

But nothing happens in the form…

I just don’t get how it works, I created zillion forms with ajax, this tool is waste of time for my now… hope I will understand and it will actually save time as it should(or maybe not ?)

you need to pass argument 3 as jquery ajax options, http://api.jquery.com/jQuery.ajax

for example

CHtml::ajaxSubmitButton('Login2', 'site/login', array('success' => 'js:function(data) { $("#login-form").prepend(data); return false;}'));

in the controller you can put something like this

// ...

if($model->validate() && $model->login()) {

  if(Yii::app()->request->isAjaxRequest) {

   echo "You're logged in";





elvan thanks for the response…

My assumption was, that when I use ajaxSubmitButton, the form will act exactlly like in normal POST…

The error hinting, and error summary, I want to see that :unsure:

Or the only way to go is to set it manually?

If I need to set it manually, it’s simpler for me to create my own form and finish it <_<

I see some advantage for normal forms, but for the modern ajax, I just don’t get why it is better to use Yii form, and don’t create my own?