/** * Rules for validation * @return array */ public function rules() { $rules = [['sex', 'required'], [['city', 'hobby', 'phone', 'url', 'nick', 'birthday'], 'used'], ['nick', 'length_max', '50'], ['city', 'length_max', '50'], ['sex', 'in', [0, 1, 2]], ['hobby', 'length_max', '50'], ['phone', 'phone'], ['url', 'url']]; // custom profile fields foreach (ProfileField::all() as $custom) { $rules[] = ['custom_data.' . $custom->id, 'used']; $rules[] = ['custom_data.' . $custom->id, (int) $custom->reg_cond === 1 ? 'direct_match' : 'reverse_match', $custom->reg_exp]; } return $rules; }
<h1><?php echo __('Profile settings'); ?> </h1> <hr /> <?php $form = new Form($model, ['class' => 'form-horizontal', 'action' => '', 'method' => 'post']); echo $form->start(); ?> <?php echo $form->field('nick', 'text', ['class' => 'form-control'], __('Enter your nickname or real name')); echo $form->field('sex', 'select', ['class' => 'form-control', 'options' => ['0' => __('Unknown'), '1' => __('Male'), '2' => __('Female')], 'optionsKey' => true], __('Choose your gender')); echo $form->field('birthday', 'text', ['class' => 'form-control'], __('Enter your birthday date in d.m.Y format')); echo $form->field('city', 'text', ['class' => 'form-control'], __('Enter the name of the city where you live')); echo $form->field('hobby', 'text', ['class' => 'form-control'], __('Enter your hobbies in comma-separated format')); echo $form->field('phone', 'text', ['class' => 'form-control'], __('Enter your phone number without spaces, if you want to make it public for other users')); echo $form->field('url', 'text', ['class' => 'form-control'], __('If you have your own homepage - enter url there')); foreach (ProfileField::all() as $custom) { echo $form->field('custom_data.' . $custom->id, 'text', ['class' => 'form-control']); } ?> <div class="col-md-9 col-md-offset-3"><?php echo $form->submitButton(__('Save'), ['class' => 'btn btn-primary']); ?> </div> <?php echo $form->finish();
/** * List additional fields * @return string * @throws \Ffcms\Core\Exception\NativeException * @throws \Ffcms\Core\Exception\SyntaxException */ public function actionFieldlist() { $records = ProfileField::all(); return $this->view->render('field_list', ['records' => $records]); }