Answer the question
In order to leave comments, you need to log in
How to connect authorization to Yii2 modal window?
The template has the following modal window with an authorization form, I built elements from the standard login.php into views into it, connected all the dependencies:
<div class="modal fade" id="enter" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="site-login">
<?php $form = ActiveForm::begin([
'id' => 'login-form',
]); ?>
<div class="modal__dialog" role="document">
<div class="modal__content">
<div class="modal__header">
<button type="button" class="modal__close" data-dismiss="modal" aria-label="Close">
<img src="images/modal-close.png" alt="">
</button>
<h4 class="modal__title">Войти на сайт</h4>
</div>
<div class="modal__body">
<div class="enter-form">
<form action="">
<div class="modal__input">
<div class="modal__label">
Ваш логин:*
</div>
<div class="modal__input-block">
<input type="text" name="username" class="input__item">
<a href="#" class="ques-icon">
<img src="images/ques-icon.png" alt="">
</a>
</div>
</div>
<div class="modal__input">
<div class="modal__label">
Пароль:*
</div>
<div class="modal__input-block">
<input type="password" name="password" class="input__item input__item_password">
<a href="#" class="forget-link">Забыли пароль?</a>
</div>
</div>
<div class="submit__input">
<?= Html::submitButton('Войти', ['class' => 'input__item', 'name' => 'login-button']) ?>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
username 'test'
password 'test'
login-button ''
Answer the question
In order to leave comments, you need to log in
There is no difference - in the modal window, the authorization form, or on the page. The main thing is that the form itself sends the correct data to the right place.
If you are submitting a form to a controller action, then you must load it in that action for validation. Those. for authorization, you need to create a LoginForm model with two (at least name/email and password) fields. In the modal window, paste the correct code:
$form = ActiveForm::begin();
echo $form->field($model, 'email');
echo $form->field($model, 'password')->passwordInput();
ActiveForm::end();
LoginForm[email] = ''
LoginForm[password] = ''
$model = new LoginForm();
if (Yii::$app->request->isPost){
if ($model->load(Yii::$app->request->post()) && $model->validate()){
... далее авторизация
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question