K
K
kolovsky_alexander2015-05-14 15:43:52
Yii
kolovsky_alexander, 2015-05-14 15:43:52

How to display error in yii2 form in right place?

It is necessary to display input errors above the registration form and not below the fields, and preferably in the
bootstrap alert component

<div class="alert alert-danger" role="alert">...</div>

I tried to display errors at least above the fields, but as a result, in any case, alert is rendered, but should only be in case of an error.
Here is the code:
$form = ActiveForm::begin(['id' => 'login-form',
                'options' => ['class' => 'form-horizontal'],
                'fieldConfig' => [
                    'template' => '
                                <div class="alert alert-danger" role="alert">{error}</div>
                                {label}<div class="col-sm-10"></div><div class="col-sm-10">{input}</div>',
                                 'labelOptions' => ['class' => 'col-sm-2 control-label'],
                 ],

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Askar Fuzaylov, 2015-05-14
@kolovsky_alexander

If the data has not been validated, use \Yii::$app->session->setFlash()it to add error texts.
And above the form, use the Alert widget https://github.com/yiisoft/yii2-app-advanced/blob/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question