1

Is it necessary to disable error output opposite the input fields? I want to display errors using getErrors() only at the top of form.

1
  • As far as I understand you don't want to show the error of each field and want to display all the error at the top? If is it so, you can set the enableClientValidation to false and then use getErrors() method to display the error at the top of your form. Commented Jun 6, 2015 at 4:07

2 Answers 2

4

If you are using the yii\widgets\ActiveForm, Try the following code:

<?php $form = ActiveForm::begin([
    'fieldConfig' => ['template' => "{label}\n{input}\n{hint}"],
]) ?>
    <?= $form->errorSummary($model) ?>
    // form fields go here
<?php ActiveForm::end(); ?>

See also yii\widgets\ActiveForm::fieldConfig, yii\widgets\ActiveField::template

Sign up to request clarification or add additional context in comments.

2 Comments

This answer would actually be the right one if you removed the {error} part from the template, and replaced the three dots (...) with some indication of that the form fields would need to go there (ie. //form fields go here or something). If you do that, and let me know here in the comment, I'd definitely vote your answer up!
I may have misunderstood. Thank you for the advice.
0

In Yii 1.0 you can comment out this peice of code in your protected/config/main.php

'errorHandler'=>array(
        // use 'site/error' action to display errors
        'errorAction'=>'site/error',
    ),

In yii 2 you need to set YII_DEBUG is false

The error handler adjusts the error display according to the value of the constant YII_DEBUG. When YII_DEBUG is true (meaning in debug mode), the error handler will display exceptions with detailed call stack information and source code lines to help easier debugging. And when YII_DEBUG is false, only the error message will be displayed to prevent revealing sensitive information about the application.

Info: If an exception is a descendant of yii\base\UserException, no call stack will be displayed regardless the value of YII_DEBUG. This is because such exceptions are considered to be caused by user mistakes and the developers do not need to fix anything.

Take a look here for more details http://www.yiiframework.com/doc-2.0/guide-runtime-handling-errors.html

1 Comment

I think you misunderstood the OP's question: they're not talking about PHP errors but about form errors. They're not looking to find an error in their script, but to change the default way of displaying form validation errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.