您好我有以下形式:Laravel 5.3,在驗證失敗會話不閃任何
<form action="{{ route('postCustomerInfo') }}" method="post" class="shipping-form">
{{ csrf_field() }}
<input type="hidden" name="note" value="hidden_note_field">
<input type="hidden" name="country_id" value="1">
<div class="form-checkout">
<div class="form-fields">
@if($errors->has('name'))<div class="input-box error" data-error="{{ $errors->first('name') }}">
@else<div class="input-box">
@endif
<input type="text" name="name" value={{ old('name') }}>
<label for="">name</label>
</div>
@if($errors->has('phone'))<div class="input-box error" data-error="{{ $errors->first('phone') }}">
@else <div class="input-box">
@endif
<input type="text" name="phone" value={{ old('phone') }} onkeypress='return event.charCode >= 48 && event.charCode <= 57'>
<label for="">phone</label>
</div>
@if($errors->has('email'))<div class="input-box error" data-error="{{ $errors->first('email') }}">
@else <div class="input-box">
@endif
<input type="text" name="email" value="{{ old('email') }}">
<label for="">email</label>
</div>
<div class="row">
<div class="col-xs-5 col-sm-5 col-md-6">
@if($errors->has('city'))<div class="input-box error" data-error="{{ $errors->first('city') }}">
@else<div class="input-box">
@endif
<input type="text" name="city" value="{{ old('city') }}">
<label for="">city</label>
</div>
</div>
<div class="col-xs-7 col-sm-7 col-md-6">
@if($errors->has('postal_code'))<div class="input-box error" data-error="{{ $errors->first('postal_code') }}">
@else<div class="input-box error" data-error="{{ $errors->first('postal_code') }}">
@endif
<input type="text" name="postal_code" value="{{ old('postal_code') }}">
<label for="">postal code</label>
</div>
</div>
</div>
@if($errors->has('address_line'))<div class="input-box error" data-error="{{ $errors->first('address_line') }}">
@else<div class="input-box error" data-error="{{ $errors->first('address_line') }}">
@endif
<input type="text" name="address_line" value={{ old('address_line') }}>
<label for="">address</label>
</div>
</div>
</div>
</form>
<a href="" class="btn action">Go to <span>shipping</span></a>
我通過jQuery
$(document).ready(function() {
$('.btn.action').on('click','',function (e) {
e.preventDefault();
var $form = $('form.shipping-form');
$form.submit();
});
});
提交表單和我FormRequest類:
class CustomerInformationRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() {
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules() {
return [
'name' => 'required|min:5|max:50',
'email' => 'required|email|min:5|max:50',
'phone' => 'required|min:3|max:20',
'country_id' => 'required',
'city' => 'required|min:3',
'postal_code' => 'required|digits:4',
'address_line' => 'required|min:5|max:50',
'note' => ''
];
}
}
我在StackOverflow中讀到這個線程:Laravel 5 input old is empty但我不認爲這實際上是我的問題。而且我的{{old('values')}}是空的,我不知道爲什麼?
你有沒有使用CustomerInformationRequest $ request在你的控制器方法中注入請求? –
是啊!公共職能customerInformation(CustomerInformationRequest $請求){ Session :: put('checkout.customer_information',$ request-> input()); } – deshi
也在我的會話中,我不能看到_old_input鍵,當我在葉片dd後提交表格 – deshi