Answer the question
In order to leave comments, you need to log in
Why do Errors and Input disappear if the input field is more than 1000 characters?
I send the form in the usual post way - I process it, validate it, when errors are found, I do
back()->withErrors($validator)->withInput();
it while there is little data - everything works, if there is an error, the form opens with errors and input, but as soon as the text field appears ~ 1000 characters, then if there is an error, Err and Input disappear , and the form is pristine?
<form method="post" action="/cart/finish">
@csrf
<label><b>*</b> Ваше имя</label>
<input class="form-control @error('name') is-invalid @enderror" name="name" value="{{old('name')}}">
@error('name') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label><b>*</b> Номер телефона</label>
<input class="form-control @error('phone') is-invalid @enderror" name="phone" value="{{old('phone')}}">
@error('phone') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label><b>*</b> E-mail</label>
<input class="form-control @error('email') is-invalid @enderror" name="email" value="{{old('email')}}">
@error('email') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label><b>*</b> Способ доставки</label>
<select name="delivery_method" class="form-control @error('delivery_method') is-invalid @enderror">
<option disabled selected></option>
<option value="1" @if(old('delivery_method')===1) selected @endif>Самовывоз</option>
<option value="2" @if(old('delivery_method')===2) selected @endif>Доставка курьером</option>
<option value="3" @if(old('delivery_method')===3) selected @endif>Почта России</option>
<option value="4" @if(old('delivery_method')===4) selected @endif>ТК "СДЭК" (До двери)</option>
<option value="5" @if(old('delivery_method')===5) selected @endif>ТК "СДЭК" (до пункта выдачи)</option>
</select>
@error('delivery_method') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label><b>*</b> Форма оплаты</label>
<select name="payment_method" class="form-control @error('payment_method') is-invalid @enderror">
<option disabled selected></option>
<option value="1" @if(old('delivery_method')===1) selected @endif>Наличными при получении</option>
<option value="2" @if(old('delivery_method')===2) selected @endif>На карту Сбербанка</option>
<option value="3" @if(old('delivery_method')===3) selected @endif>Безналичная оплата по счету</option>
</select>
@error('payment_method') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label>Адрес доставки</label>
<textarea name="delivery_address" class="form-control @error('delivery_address') is-invalid @enderror">{{old('delivery_address')}}</textarea>
@error('delivery_address') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label>Комментарий к заказу</label>
<textarea name="comment" class="form-control @error('comment') is-invalid @enderror">{{old('comment')}}</textarea>
@error('comment') <div class="invalid-feedback"> {{ $message }} </div> @enderror
</form>
public function cart_finish(Request $request) {
$validator = Validator::make($request->all(), [
'name' => 'required|max:60',
'phone' => 'required|max:20',
'email' => 'required|email|max:60',
'delivery_method' => 'required|integer',
'payment_method' => 'required|integer',
'delivery_address' => 'max:300',
'comment' => 'max:300',
]);
if ($validator->fails()) {
return back()
->withErrors($validator)
->withInput();
}
public function cart_checkout(Request $request) {
$cart = Order::getCart();
return view('cart_checkout', [
'website' => Website::instance(),
'cart' => $cart
]);
}
Answer the question
In order to leave comments, you need to log in
the problem, as it turned out, was that the cookie session driver was set . after changing to file it leaves.
which is actually understandable, since cookies have a size limit. lara does not check the size of cookies before sending.
There was a similar problem. For a long time I could not understand what was the matter, in the end I understood.
The point here is not the number of characters entered in the input field, but the number of these very fields that do not pass validation.
Example:
I had 11 fields. Everything is under the validator. If I don't fill them all out, I come back without any mention of errors. That is, $errors is empty. If I start to reduce the number of empty fields, for example, to 6, then everything works fine.
Why is this happening?
Surely your error output is Russified? So, the fact is that English characters have a size of 1 bit, and Russian 2 (1 bit of the character itself and 1 bit of the language sign). Somewhere, probably, a limit is set on the size of this variable. That's why this shit happens.
How did I decide?
A line in the validation.php file
'required' => 'Поле ":attribute" обязательно для заполнения.',
'required' => 'Заполни ":attribute"',
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question