chux
(Djchux)
May 1, 2011, 7:04pm
1
Hi,
Im trying to do a user registration form, using CActiveForm, ajax validation and client side validation. I have read this in the user guide
The AJAX-based validation and client-side validation may be used together or separately. For example, in a user registration form, one may use AJAX-based validation to check if the user has picked a unique username, and use client-side validation to ensure all required fields are entered with data. Because the AJAX-based validation may bring extra workload on the server, if possible, one should mainly use client-side validation.
But, how do i define that i want the validation only for the username? i want client side validation for all fields (that is working ok) but i want ajax validation only for username field (now, ajax validation is triggering for every field)
This is what i have:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'usuario-form',
'enableClientValidation'=>true,
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
),
'focus' => array($model, 'login'),
));
Thanks
bamdadd
(Bamdadd)
May 1, 2011, 7:16pm
2
chux:
Hi,
Im trying to do a user registration form, using CActiveForm, ajax validation and client side validation. I have read this in the user guide
But, how do i define that i want the validation only for the username? i want client side validation for all fields (that is working ok) but i want ajax validation only for username field (now, ajax validation is triggering for every field)
This is what i have:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'usuario-form',
'enableClientValidation'=>true,
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
),
'focus' => array($model, 'login'),
));
Thanks
hi
i think you should override clientValidateAttribute() and implement your own validation with Javascript.
check this : http://www.yiiframework.com/doc/api/1.1/CValidator#clientValidateAttribute-detail
chux
(Djchux)
May 1, 2011, 7:22pm
3
Hi,
Thanks for your reply. What you say is for custom client validation, right? this is working ok.
What i want to do is trigger the ajax validation only for the username field, as described in CActiveForm documentation.
chux
(Djchux)
May 1, 2011, 7:34pm
4
Found it:
http://www.yiiframework.com/doc/api/1.1/CActiveForm#error-detail
So, i have to set the 4th parameter to false:
Login will trigger ajax validation:
<?php echo $form->error($model,'login'); ?>
Name will validate only in client side:
<?php echo $form->error($model,'name', array(), false); ?>
I hope this will help someone in the future.
Thanks!