Answer the question
In order to leave comments, you need to log in
Ajax validation in Yii. Why is a validation error not displayed for the uniqueness of the field?
Several validation parameters are set for the form, including the uniqueness of the field value.
yii honestly fulfills other validation rules and gives an error in the form, but if you enter a value that is already in the database (validation for a unique value), there will be no error on the client and the form will be sent, but the server will not skip the value and will not write it to the database .
public function rules() {
return array(
array('username, password, email', 'required'),
array('username', 'unique', 'className'=>'Users', 'message'=>'Данный логин занят' ),
array('username', 'length', 'min'=>3, 'max'=>20),
array('email', 'email'),
array('password', 'length', 'min'=>5, 'max'=>100),
array('id, username', 'safe', 'on'=>'search'),
);
}
$form=$this->beginWidget('CActiveForm', array(
'id'=>'registr-form',
'enableClientValidation'=>true,
'action'=>Yii::app()->createUrl('/site/CreateProfil'),
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
));
echo '<label for="login">Логин:</label>';
echo $form->textField($model,'username', array('class'=>"input_text"));
echo $form->error($model,'username');
echo '<label for="password">Пароль:</label>';
echo $form->passwordField($model,'password', array('class'=>"input_text"));
echo $form->error($model,'password');
echo '<label for="login">E-mail:</label>';
echo $form->textField($model,'email', array('class'=>"input_text"));
echo $form->error($model,'email');
echo CHtml::submitButton('Создать', array('class'=>"btn"));
$this->endWidget();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question