Client Side Validation

Hi. I use this code:


<?php

	$quickLogin = $this->beginWidget('CActiveForm', array(

		'id' => 'quickLogin',

		'enableAjaxValidation' => true,

		'enableClientValidation'=> false,

		'action' => array('/user/auth/validateAuth')

	));    

?>

    

	<div class="row" style="margin-top: 40px;">

		<?=$quickLogin->label($model,'username', array('label' => 'Логин:')); ?>

		<?=$quickLogin->textField($model,'username', array('size' => 10)) ?>

	</div>

	

	<div class="row">

		<?=$quickLogin->labelEx($model,'password', array('label' => 'Пароль:')); ?>

		<?=$quickLogin->passwordField($model,'password', array('size' => 10)); ?>

	</div>

	

	<div class="row submit" style="margin-bottom: 30px;">

		<?=CHtml::ajaxSubmitButton('Войти', 

				Yii::app()->createAbsoluteUrl('/user/auth/validateAuth'), 

				array(

					'dataType' => 'json',

					'type' => 'POST',

					'success' => ''

				),

				array('type' => 'submit'));?>

	</div>

	

	<div class="formErrors">

		<?=$quickLogin->error($model, 'username')?>

		<?=$quickLogin->error($model, 'password')?>

		<div id="other" style="display: none;"></div>

	</div>

        

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



So, I use ajax validation. And I don’t want to use client side validation. I set enableClientValidation parametr to false. But it still work. How can i disable it.

Hi psevdo,

Is what you see really client validation? I mean, you might mistake ajax validation as client validation.

Would you please elaborate what you expect and what you get regarding the functionality of your login form?

For example. I fill field a username. Then I try to fill a email field. So, at this moment validation performed. I think it is a client side validation.

Check the html output of your login form to see if it has some javascript code to perform the client validation. If it is enabled, you will see something like this:




jQuery('#contact-form').yiiactiveform(

    {'validateOnSubmit': true, 'attributes': [

        {

            'id': 'ContactForm_name',

            'inputID': 'ContactForm_name',

            'errorID': 'ContactForm_name_em_',

            'model': 'ContactForm',

            'name': 'name',

            'enableAjaxValidation': true,

            'clientValidation': function (value, messages, attribute) {

                if (jQuery.trim(value) == '') {

                    messages.push("\u304a\u540d\u524d \u306f\u7a7a\u767d\u3067\u306f\u3044\u3051\u307e\u305b\u3093\u3002");

                }

        }},

        ...

    ], 'focus': 'input:text[value=\"\"]:first'});



This is for ‘required’ field.

And, check ‘clientOptions’ property of CActiveForm in the reference.

http://www.yiiframework.com/doc/api/1.1/CActiveForm#clientOptions-detail

Probably you just have to set ‘validateOnChange’ to false, overriding the default value of true.

And I think you’d better set ‘validateOnSubmit’ to true and use a normal submit button instead of ajax submit button.

I haven’t this code. Now I know I disabled client side validation. Then I set validateOnChange parametr to false. Now my validation work how I want. Thanks.

Hi,

please see this…

http://www.yiiframework.com/forum/index.php/topic/43977-ajax-client-side-validation-without-refreshing-page/page__p__208536__fromsearch__1#entry208536

i hope it’s some help.