I don’t mind client validation being on BEFORE they submit the form, but I’m trying to see if there is anyway I can disable it showing errors under each form field AFTER submit as I’m showing the errors in my own custom location.
I tried doing this:
<?php $form = ActiveForm::begin(['enableClientValidation' => false, 'enableError' => false]); ?>
But I got the error:
Setting unknown property: yii\bootstrap\ActiveForm::enableError
But then I noticed this appears to only for the ActiveField and not ActiveForm .
Is there anyway to do what I want without having to set it for every field?
flarpy
(Peter)
December 23, 2014, 4:51pm
2
I recommend you use the {error} syntax from the inputTemplate rather than doing your own custom code to display errors, it will make your life much easier!
See http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html#$inputTemplate-detail
Well all I do is basically:
$errors = general::formatErrors($model->errors);
formatErrors is basically just a method that wraps each error in the array in a <p></p> tag; then I do something like:
return $this->render('login', ['model' => $user, 'errors' => $errors]);
Then in the view:
<?php echo ($errors) ? '<div class="alert alert-danger" role="alert">' . $errors . '</div>' : ''; ?>
Are you saying I can display the errors where I want in an easier fashion?
flarpy
(Peter)
December 23, 2014, 7:59pm
4
Yes, much easier, no custom methods, just place the {error} placeholder where you want it on the page and it will "magically" appear!
Hold on… isn’t that just for one specific field (input field)? Hence the name…
I need it to display whatever is in $model->errors