I’m try to use max
rule set to 2000 in textarea
, but I put more than 2000 character the validation is not work for other input fields and the page reload with empty input value the problem still even when I try the number of character less then 2000, when I hit add with empty textarea
the required validate is work, I had try also to change max to size and still same problem.
I want to validate textarea
with old input value back in next request and if number of character more then 2000 display the error message.
I can use javascript
or maxlength
attribute in html but want to do it from server side.
The validation failed for all input when textarea
have 974 characters
- Laravel version 6
- Xampp version 3.2.4
- Php version 7.3.9
Blade
<form method="POST" action="{{ route('problems.store', auth()->user()) }}">
@csrf
<h6 class="heading-small text-muted mb-4">{{ __('Problem information') }}</h6>
<div class="pl-lg-4">
<!-- alert -->
@if ($errors->any())
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
@endif
<!-- Account Number input -->
<div class="form-group{{ $errors->has('Account_Number') ? ' has-danger' : '' }}">
<label class="form-control-label"
for="input-account-number">{{ __('Account Number') }}</label>
<div class="input-group input-group-alternative mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-user-circle"></i></span>
</div>
<input class="form-control{{ $errors->has('Account_Number') ? ' is-invalid' : '' }}"
placeholder="{{ __('Account Number') }}" type="text" name="Account_Number"
value="{{ old('Account_Number') }}" autofocus>
</div>
@if ($errors->has('Account_Number'))
<span class="invalid-feedback" style="display: block;" role="alert">
<strong>{{ $errors->first('Account_Number') }}</strong>
</span>
@endif
</div>
<!-- Account Name input -->
<div class="form-group{{ $errors->has('Account_Name') ? ' has-danger' : '' }}">
<label class="form-control-label"
for="input-account-name">{{ __('Account Name') }}</label>
<div class="input-group input-group-alternative mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-id-card"></i></span>
</div>
<input class="form-control{{ $errors->has('Account_Name') ? ' is-invalid' : '' }}"
placeholder="{{ __('Account Name') }}" type="text" name="Account_Name"
value="{{ old('Account_Name') }}" autofocus>
</div>
@if ($errors->has('Account_Name'))
<span class="invalid-feedback" style="display: block;" role="alert">
<strong>{{ $errors->first('Account_Name') }}</strong>
</span>
@endif
</div>
<!-- Email input -->
<div class="form-group{{ $errors->has('email') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-email">{{ __('Email') }}</label>
<div class="input-group input-group-alternative mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-envelope"></i></span>
</div>
<input class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}"
placeholder="{{ __('Email') }}" type="email" name="email"
value="{{ old('email') }}">
</div>
@if ($errors->has('email'))
<span class="invalid-feedback" style="display: block;" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<!-- Date input -->
<div class="form-group{{ $errors->has('Date') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-data">{{ __('Date') }}</label>
<div class="input-group input-group-alternative mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
</div>
<input class="form-control{{ $errors->has('Date') ? ' is-invalid' : '' }}"
placeholder="{{ __('Date') }}" type="date" name="Date" value="{{ old('Date') }}"
min="2005-01-01" max="2025-12-31" autofocus>
</div>
@if ($errors->has('Date'))
<span class="invalid-feedback" style="display: block;" role="alert">
<strong>{{ $errors->first('Date') }}</strong>
</span>
@endif
</div>
<!-- problem description input -->
<div class="form-group{{ $errors->has('problem_descrip') ? ' has-danger' : '' }}">
<label class="form-control-label"
for="input-problem-description">{{ __('Problem Description') }}</label>
<div class="input-group input-group-alternative mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-file-alt"></i></span>
</div>
<!-- the problem here -->
<textarea class="form-control{{ $errors->has('problem_descrip') ? ' is-invalid' : '' }}"
name="problem_descrip" rows="2"
placeholder="{{ __('Descrip the problem here') }}">{{ old('problem_descrip') }}</textarea>
</div>
@if ($errors->has('problem_descrip'))
<span class="invalid-feedback" style="display: block;" role="alert">
<strong>{{ $errors->first('problem_descrip') }}</strong>
</span>
@endif
</div>
<!-- added by input -->
<div class="form-group">
<label class="form-control-label" for="input-added_by">{{ __('Added By') }}</label>
<div class="input-group input-group-alternative mb-3">
<div class="input-group-prepend">
<span class="input-group-text" style="background-color: #e9ecef"><i lass="fas fa-user-tie"></i></span>
</div>
<input class="form-control" type="text" value="{{ auth()->user()->name }}" disabled>
</div>
</div>
<hr class="my-4"/>
<h6 class="heading-small text-muted mb-4">{{ __('Solved') }}</h6>
<!-- Comment input -->
<div class="form-group{{ $errors->has('comment') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-comment">{{ __('Comment') }}</label>
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-comment"></i></i></span>
</div>
<textarea class="form-control{{ $errors->has('comment') ? ' is-invalid' : '' }}"
name="comment" rows="2"
placeholder="{{ __('comment on the problem or solution') }}">{{ old('comment') }}</textarea>
</div>
@if ($errors->has('comment'))
<span class="invalid-feedback" style="display: block;" role="alert">
<strong>{{ $errors->first('comment') }}</strong>
</span>
@endif
</div>
<!-- added by input -->
<label class="form-control-label" for="input-added_by">{{ __('Solved By') }}</label>
<div class="input-group input-group-alternative mb-2">
<div class="input-group-prepend">
<span class="input-group-text" style="background-color: #e9ecef"><i class="fas fa-user-tie"></i></span>
</div>
<input class="form-control" type="text" value="{{ auth()->user()->name }}" disabled>
</div>
<!-- Solved checkbox -->
<div class="custom-control custom-checkbox mb-3">
<div class="input-group{{ $errors->has('Sovled') ? ' has-danger' : '' }} mb-2">
<input type='hidden' value='0' name='Sovled'>
<input class="custom-control-input" id="customCheck1" name="Sovled" value="1"
type="checkbox">
<label class="custom-control-label" for="customCheck1">{{ __('Solved') }}</label>
</div>
@if ($errors->has('Sovled'))
<span class="text-danger ml--4" role="alert">
<b>{{ $errors->first('Sovled') }}</b>
</span>
@endif
</div>
<!-- submit button -->
<div class="text-center">
<button type="submit" class="btn btn-primary mt-4">{{ __('Add') }}</button>
</div>
</div>
</form>
method used in controller
public function store(Request $request, User $user)
{
$rules = [
'Account_Number' => ['required', 'numeric'],
'Account_Name' => ['required', 'string'],
'email' => ['required', 'email', 'max:20'],
'Date' => ['required', 'date_format:Y-m-d'],
'problem_descrip' => ['required', 'min:1', 'max:2000'], // max not work
'comment' => ['nullable', 'string', 'required_if:Sovled,1', 'min:0', 'max:2000'], // something
'Sovled' => ['nullable', 'numeric', new Checkbox($request->get('comment'), $request->get('Sovled'))]
];
$customMessages = [
'comment.required_if' => 'The :attribute field can not be blank when solved box is checked you need to write the solution.'
];
$result = Validator::make($request->all(), $rules, $customMessages);
if ($result->fails()) {
return redirect()->back()->withErrors($result)->withInput($request->input());
}
dd($request->all());
//$request->user->id
}
The Problem
2
Answers
Try This, You Must Add Of Aliases STRING, Because Max Detected For Size Of File. Good Luck, Please UP Button If Helping Your Problem :).
It looks like a session problem, try changing session driver from cookie to file in
.env