Is it necessary to disable error output opposite the input fields? I want to display errors using getErrors() only at the top of form.
-
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.Chinmay Waghmare– Chinmay Waghmare2015-06-06 04:07:19 +00:00Commented Jun 6, 2015 at 4:07
2 Answers
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
2 Comments
{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!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