I am trying to expand the registration form, add new fields to the standard fields, for example, a telephone.

the form

<?= $form->field($model, 'username', [ 'inputOptions' => ['placeholder' => 'Название'], 'inputTemplate' => '<div class="form-group form-group-feedback form-group-feedback-left">{input}<div class="form-control-feedback"> <i class="icon-link text-muted"></i></div></div>' ]) -> label(false); ?> <?= $form->field($model, 'email', [ 'inputOptions' => ['placeholder' => 'email'], 'inputTemplate' => '<div class="form-group form-group-feedback form-group-feedback-left">{input}<div class="form-control-feedback"> <i class="icon-mention text-muted"></i></div></div>' ]) -> label(false); ?> <?= $form->field($model, 'telephone', [ 'inputOptions' => ['placeholder' => 'телефон'], 'inputTemplate' => '<div class="form-group form-group-feedback form-group-feedback-left">{input}<div class="form-control-feedback"> <i class="icon-iphone text-muted"></i></div></div>' ]) -> label(false); ?> <?= $form->field($model, 'password', [ 'inputOptions' => ['placeholder' => 'пароль'], 'inputTemplate' => '<div class="form-group form-group-feedback form-group-feedback-left">{input}<div class="form-control-feedback"> <i class="icon-user-lock text-muted"></i></div></div>' ]) -> label(false)->passwordInput(); ?> 

after pressing the button, the data goes to the controller

 $user = $model->signup() 

from controller to model

 public $username; public $email; public $password; public $telephone; public function signup() { if (!$this->validate()) { return null; } $user = new User(); $user->username = $this->username; $user->telephone = $this->telephone; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); return $user->save() ? $user : null; } 

and here it turns out $user->telephone = $this->telephone; NULL if to see print_r($_POST); everything is there, maybe I didn’t do it or didn’t finish it

    1 answer 1

    Checked it in the rules? Since by default all attributes not listed in the rules of the model are unsafe, i.e. not safe and in case of not obvious assignment (via load or setAttributes) will be ignored.