Answer the question
In order to leave comments, you need to log in
The data itself is saved in the form without having time to click on the button?
In the modal window, I fill out the registration form and before I even click on the button, it already flies to save, and when I click the button, it says This mail is already busy, in short, registered ....
How to make registration occur after clicking on the button and after if everything is ok, the form was closed and popped up
Yii::$app->session->setFlash('success', 'Письмо с активацией отправлено на емайл <strong>' . Html::encode($user->email) . '</strong> (проверьте папку спам).');
<?php $form = ActiveForm::begin([
'id' => 'reg-form',
'enableAjaxValidation' => true,
]); ?>
<?= $form->field($model, 'name')->textInput() ?>
<?= $form->field($model, 'surname')->textInput() ?>
<?= $form->field($model, 'email')->textInput() ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'password_repeat')->passwordInput() ?>
<?= Html::submitButton('Зарегистрироваться') ?>
<?php ActiveForm::end(); ?>
public function actionSignUp()
{
$emailActivation = Yii::$app->params['emailActivation'];
$model = $emailActivation ? new Signup(['scenario' => 'emailActivation']) : new Signup();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && $model->validate()) {
if ($user = $model->signup()) {
if ($user->status === User::STATUS_ACTIVE) {
if (Yii::$app->getUser()->login($user)) {
return $this->goHome();
}
} else {
if ($model->sendActivationEmail($user)) {
Yii::$app->response->format = Response::FORMAT_JSON;
Yii::$app->session->setFlash('success', 'Письмо с активацией отправлено на емайл <strong>' . Html::encode($user->email) . '</strong> (проверьте папку спам).');
return ActiveForm::validate($model);
} else {
Yii::$app->session->setFlash('error', 'Ошибка. Письмо не отправлено.');
Yii::error('Ошибка отправки письма.');
}
}
} else {
Yii::$app->session->setFlash('error', 'Возникла ошибка при регистрации.');
Yii::error('Ошибка при регистрации');
return $this->refresh();
}
}
return $this->renderAjax('sign-up', ['model' => $model]);
}
Answer the question
In order to leave comments, you need to log in
Goodnight.
Remove 'enableAjaxValidation' => true
Transfer to model&& $model->validate()
enableAjaxValidation => true
Validation via ajax, so not surprising, but you can set it up on submit
'enableAjaxValidation' => true,
'validateOnBlur' => false,
'validateOnChange' => false,
'validateOnType' => false,
'validateOnSubmit' => true,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question