Мне нужно при регистрации пользователя, чтобы он выбирал одну из двух радиокнопок, а данные об этом заносились в БД ввиде значений 1 или 2.
View:
Signup.php
<?php
/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\SignupForm */
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
$this->title = 'Signup';
$this->params['breadcrumbs'][] = $this->title;
?>
</header>
<section class="login__form">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="formHeading">Signup</div>
<form action="" class="loginForm">
<div class="input_container">
<?php $form = ActiveForm::begin(['id' => 'form-signup']); ?>
<p class="form__input__title">E-mail</p>
<?= $form->field($model, 'email')->textInput(['autofocus' => true, 'class' => 'inputs'])->label(false) ?>
<p class="form__input__title">Nickname/Company</p>
<?= $form->field($model, 'username')->textInput(['autofocus' => true, 'class' => 'inputs'])->label(false) ?>
<p class="form__input__title">Password</p>
<?= $form->field($model, 'password')->passwordInput()->label(false) ?>
<label><?= $form->field($model,'account_type')->radioList( ['1'=>'Searching Job', '2'=>'Company'], array('separator'=>' ')) ?></label>
<br>
<?= Html::submitButton('Sign Up', ['class' => 'button__to accent button__sumbit', 'name' => 'signup-button']) ?>
<?php ActiveForm::end(); ?>
</div>
</form>
</div>
</div>
</div>
</section>
SignupForm:<?php
namespace frontend\modules\User\models;
use yii\base\Model;
use frontend\models\User;
/**
* Signup form
*/
class SignupForm extends Model
{
public $username;
public $email;
public $password;
public $account_type;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
['username', 'trim'],
['username', 'required'],
['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
['username', 'string', 'min' => 2, 'max' => 255],
['account_type', 'required'],
['email', 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'string', 'max' => 255],
['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
['password', 'required'],
['password', 'string', 'min' => 6],
];
}
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if (!$this->validate()) {
return null;
}
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
return $user->save() ? $user : null;
}
}