Answer the question
In order to leave comments, you need to log in
Is it possible to get form validation errors without yii2 widgets?
In general, I decided to make a form, but not based on activeForm, since it is more expensive to style ActiveForm, but with a simple layout. But I thought that by tearing out some blocks and classes from the generated ActiveForm form, I could resurrect the validation.
I created such a form, specifying the id and name needed for the inputs, I didn’t forget about my friend csrf
<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
Answer the question
In order to leave comments, you need to log in
In general, you have three options.
The first way, I took the form that you gave in the question as a basis, I think that this one will suit you.
<?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',
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question