Answer the question
In order to leave comments, you need to log in
How in laravel, when an error occurs in form validation, to visually show which field has an error?
SUBJECT. After submitting the form, the information gets into the validator. If the validator finds an error, it will redirect back to the form with an array of errors. In general, this is all the documentation describes in detail how to display these errors and so on. I'm interested in something else - how to highlight fields with an error, and, preferably, indicate the error itself under each field?
I managed to do this using all the constructions from the documentation, but the code turned out, to put it mildly, poorly readable. I'm sure there is a way to make it easier. Here is the code:
<input class="form-control" name="inn" type="text" value="{{ old('inn') }}">
<div class="div_error">
{{ $errors->first('inn') }}
@if( session('bad_inn') == 1 )
Неправильное ИНН
@endif
</div>
Answer the question
In order to leave comments, you need to log in
Typical bootstrap construction:
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<input id="password" placeholder="Пароль" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question