Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2. //код в представлении
  3.  
  4.                 $form = $this->beginWidget('CActiveForm',array(
  5.                     'enableClientValidation'=>true,
  6.                     'id'=>'ActiveFormTest',
  7.                     'method'=>'post',
  8.                     'clientOptions' => array(
  9.                         'validateOnSubmit' => true,
  10.                         'validateOnChange' => true,
  11.                         'validateOnType' => true,
  12.                         'afterValidate' => 'js:console.log("tested")'
  13.                     )
  14.                 ));
  15.                
  16.                 $model = new Validator();
  17.                
  18.                 echo$form->errorSummary($model);
  19.                
  20.                 echo $form->label($model,'name');
  21.                 echo $form->textField($model,'name');
  22.                 echo $form->error($model,'name');
  23.                 echo '<br>';
  24.                 echo $form->label($model,'surname');
  25.                 echo $form->textField($model,'surname');
  26.                 echo $form->error($model,'surname');
  27.                 echo '<br>';
  28.                
  29.                 echo CHtml::submitButton('Отправить');
  30.                 php $this->endWidget();
  31. ?>
  32.  
  33.  
  34.  
  35.  
  36. //код модели
  37. <?php
  38.  
  39. class Validator extends CFormModel
  40. {
  41.     public $name,$surname,$secondName,$sex;
  42.  
  43.     /**
  44.      * Declares the validation rules.
  45.      * The rules state that username and password are required,
  46.      * and password needs to be authenticated.
  47.      */
  48.     public function rules()
  49.     {
  50.         return array(
  51.             array('name, secondName,surname', 'match','pattern'=>'/[a-zA-Zа-яА-ЯёЁ\-\s]+/','message'=>'Необходимо ввести значение'),
  52.             array('sex', 'boolean', 'message'=>'Необходимо выбрать пол')
  53.         );
  54.     }
  55.  
  56.     /**
  57.      * Declares attribute labels.
  58.      */
  59.     public function attributeLabels()
  60.     {
  61.         return array(
  62.             'name'=>'Имя',
  63.             'surname'=>'Фамилия',
  64.             'secondName'=>'Отчество',
  65.             'sex'=>'пол',
  66.             'birthdate'=>'дата рождения'
  67.         );
  68.     }
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement