<form id="login-form" class="login100-form validate-form form-horizontal" action="/login" method="post">
<input type="hidden" name="<?=Yii::$app->request->csrfParam; ?>" value="<?=Yii::$app->request->getCsrfToken(); ?>" />
<span class="login100-form-title">
Авторизация
</span>
<div class="form-group wrap-input100 validate-input field-loginform-username required">
<input id="loginform-username" class="form-control input100" type="text" name="LoginForm[username]" placeholder="Логин">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-envelope" aria-hidden="true"></i>
</span>
<p class="help-block help-block-error "></p>
</div>
<div class="form-group wrap-input100 validate-input field-loginform-password required has-error">
<input id="loginform-password" class="form-control input100" type="password" name="LoginForm[password]" placeholder="Пароль">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-lock" aria-hidden="true"></i>
</span>
<p class="help-block help-block-error "></p>
</div>
<div class="container-login100-form-btn">
<button name="login-button" type="submit" class="login100-form-btn">
Войти
</button>
</div>
<div class="text-center p-t-12">
<div class="form-group field-loginform-rememberme txt1">
<div class="col-lg-offset-1 col-lg-3"><input type="hidden" name="LoginForm[rememberMe]" value="0"><input type="checkbox" id="loginform-rememberme" name="LoginForm[rememberMe]" value="1" checked=""> <label for="loginform-rememberme">Запомнить меня</label></div>
<div class="col-lg-8"><p class="help-block help-block-error "></p></div>
</div>
</div>
<div class="text-center p-t-136">
<p class="help-block help-block-error "></p>
</div>
</form
<?php
$model = new LoginForm;
$form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'login100-form validate-form form-horizontal'],
'fieldConfig' => [
'options' => ['class' => 'form-group wrap-input100 validate-input'],
'template' => "{input}\n<span class=\"focus-input100\"></span>{label}\n{hint}\n{error}",
'labelOptions' => ['class' => 'symbol-input100'],
'inputOptions' => ['class' => 'form-control input100']
],
]);
?>
<span class="login100-form-title">
Авторизация
</span>
<?= $form->field($model, 'username')->textInput(['placeholder' => 'Логин'])->label('<i class="fa fa-envelope" aria-hidden="true"></i>') ?>
<?= $form->field($model, 'password')->textInput(['placeholder' => 'Пароль'])->label('<i class="fa fa-lock" aria-hidden="true"></i>') ?>
<div class="container-login100-form-btn">
<?= Html::submitButton('Войти', ['class' => 'login100-form-btn', 'name' => 'login-button']) ?>
</div>
<?= $form->field($model, 'rememberMe', ['template' => '<div class="text-center p-t-12"><div class="form-group field-loginform-rememberme txt1"><div class="col-lg-offset-1 col-lg-3">{input}</div></div></div>'])->checkbox() ?>
<?php
ActiveForm::end();
?>
public $depends = [
'yii\web\YiiAsset',
];
<?php
namespace app\models\user\forms;
use Yii;
use yii\base\Model;
use app\models\user\User;
class RegisterForm extends Model
{
public $firstname;
public $lastname;
public $email;
public $email_repeat;
public $password;
public $password_repeat;
public function rules()
{
return [
[['firstname', 'lastname', 'email', 'email_repeat', 'password', 'password_repeat'], 'required'],
[['firstname', 'lastname','email', 'email_repeat', 'password', 'password_repeat'], 'trim'],
[['firstname', 'lastname'], 'string', 'min'=>2, 'max'=>20],
[['password'], 'string', 'min'=>6, 'max' => 12],
[['password_repeat'], 'compare', 'compareAttribute'=>'password', 'message'=>"Password dont match"],
[['email_repeat'], 'compare', 'compareAttribute'=>'email', 'message'=>"Email dont match"],
[['email'], 'email'],
[['email'], 'checkUniqueEmail']
];
}
public function register()
{
// $firstname, $lastname, $email, $password
$user = new User();
$user->firstname = $this->firstname;
$user->lastname = $this->lastname;
$user->email = $this->email;
$user->password = $user->setPassword($this->password);
$user->auth_key = $user->generateToken();
$user->email_token = $user->generateToken();
$user->status = User::USER_INACTIVE;
$user->created_at = time();
$user->updated_at = time();
return $user->save();
}
public function checkUniqueEmail($attribute, $params)
{
$email = User::find()->where(['email'=> $this->email])->one();
if ($email)
{
$this->addError($attribute, 'email exists');
return false;
}
}
}
public function actionTest()
{
$model = new RegisterForm();
if($model->load(Yii::$app->request->post()))
{
if ($model->validate())
{
$model->register();
}
}
return $this->render('test',[
'model' => $model,
]);
}
use yii\helpers\Html;
<?= Html::beginForm(['site/test'], 'post', ['enctype' => 'multipart/form-data', 'class' => 'reg-fr']) ?>
<?= Html::input('text', 'RegisterForm[firstname]', null, ['class' => 'tes']) ?>
<?= Html::error($model, 'firstname') ?>
<?= Html::input('text', 'RegisterForm[lastname]', null, ['class' => 'hello']) ?>
<?= Html::error($model, 'lastname') ?>
<?= Html::input('text', 'RegisterForm[email]', null, ['class' => 'hello']) ?>
<?= Html::error($model, 'email') ?>
<?= Html::input('text', 'RegisterForm[email_repeat]', null, ['class' => 'hello']) ?>
<?= Html::error($model, 'email_repeat') ?>
<?= Html::input('text', 'RegisterForm[password]', null, ['class' => 'hello']) ?>
<?= Html::error($model, 'password') ?>
<?= Html::input('text', 'RegisterForm[password_repeat]', null, ['class' => 'hello']) ?>
<?= Html::error($model, 'password_repeat') ?>
<input type="submit" value="send">
<?= Html::endForm() ?>