Php Laravel 5.3验证失败时不保留旧输入的表格
我有一个表单,用户可以在其中创建一个项目。但是,当表单提交且未通过验证时,旧的输入不会被记住,只会被删除,这对用户来说是令人沮丧的 我使用的是laravelcollective表单,我的html如下所示:Php Laravel 5.3验证失败时不保留旧输入的表格,php,forms,laravel,laravel-5,laravel-form,Php,Forms,Laravel,Laravel 5,Laravel Form,我有一个表单,用户可以在其中创建一个项目。但是,当表单提交且未通过验证时,旧的输入不会被记住,只会被删除,这对用户来说是令人沮丧的 我使用的是laravelcollective表单,我的html如下所示: {{ Form::open(['route' => 'my.route', 'class' => 'form-horizontal', 'files' => true]) }} <div class="form-group"> {{ Form::lab
{{ Form::open(['route' => 'my.route', 'class' => 'form-horizontal', 'files' => true]) }}
<div class="form-group">
{{ Form::label('name', 'Name', ['class' => 'control-label col-md-3']) }}
<div class="col-md-9">
{{ Form::text('name', null, ['placeholder' => 'hello world' ,'class' => 'form-control']) }}
</div>
</div>
<div class="form-group">
{{ Form::label('description', 'Description', ['class' => 'control-label col-md-3']) }}
<div class="col-md-9">
{{ Form::textarea('description', null, ['placeholder' => 'hello world', 'class' => 'form-control']) }}
<span>some sub-text</span>
</div>
</div>
<div class="form-group">
{{ Form::label('date', 'Date', ['class' => 'control-label col-md-3']) }}
<div class="col-md-9">
{{ Form::text('date', null, ['placeholder' => 'hello world', 'class' => 'form-control']) }}
</div>
</div>
{{ Form::close() }}
我将项目存储在后端的方法如下所示,其中ItemRequest负责验证
public function store(ItemRequest $request, ImageMagick $imageMagick)
{
$item = new Item;
$item->name = $request->name;
$item->description = $request->description;
$item->date = $request->date;
$item->save();
return redirect()->route('some.other.route');
}
试图确定旧输入不被记住的原因 使用重定向路由方法末尾的方法,如下所示:
// If validation failed, use this method to make the old inputs available in the view
return redirect()->route('some.other.route')->withInput();
了解更多关于
希望这有帮助 使用重定向路由方法末尾的方法,如下所示:
// If validation failed, use this method to make the old inputs available in the view
return redirect()->route('some.other.route')->withInput();
了解更多关于
希望这有帮助 当验证失败时,不会调用此函数,因为他使用表单请求。@Vuldo-Nice catch,我已经更新了我的答案!谢谢:当验证失败时不会调用此函数,因为他使用表单请求。@Vuldo-很好,我已经更新了我的答案!谢谢:您可以发布
ItemRequest
请发布ItemRequest
请