Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //код в представлении
- $form = $this->beginWidget('CActiveForm',array(
- 'enableClientValidation'=>true,
- 'id'=>'ActiveFormTest',
- 'method'=>'post',
- 'clientOptions' => array(
- 'validateOnSubmit' => true,
- 'validateOnChange' => true,
- 'validateOnType' => true,
- 'afterValidate' => 'js:console.log("tested")'
- )
- ));
- $model = new Validator();
- echo$form->errorSummary($model);
- echo $form->label($model,'name');
- echo $form->textField($model,'name');
- echo $form->error($model,'name');
- echo '<br>';
- echo $form->label($model,'surname');
- echo $form->textField($model,'surname');
- echo $form->error($model,'surname');
- echo '<br>';
- echo CHtml::submitButton('Отправить');
- php $this->endWidget();
- ?>
- //код модели
- <?php
- class Validator extends CFormModel
- {
- public $name,$surname,$secondName,$sex;
- /**
- * Declares the validation rules.
- * The rules state that username and password are required,
- * and password needs to be authenticated.
- */
- public function rules()
- {
- return array(
- array('name, secondName,surname', 'match','pattern'=>'/[a-zA-Zа-яА-ЯёЁ\-\s]+/','message'=>'Необходимо ввести значение'),
- array('sex', 'boolean', 'message'=>'Необходимо выбрать пол')
- );
- }
- /**
- * Declares attribute labels.
- */
- public function attributeLabels()
- {
- return array(
- 'name'=>'Имя',
- 'surname'=>'Фамилия',
- 'secondName'=>'Отчество',
- 'sex'=>'пол',
- 'birthdate'=>'дата рождения'
- );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement