在Laravel 4中重定向回时保留表单值 [英] Keep form values when redirect back in Laravel 4
本文介绍了在Laravel 4中重定向回时保留表单值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在Laravel 4上执行Redirect :: back时,我试图保留表单的值,但是我找不到执行此操作的方法.
I'm trying to keep the values of a form when Redirect::back on Laravel 4, but I can't find a way to do this.
这是我的表格:
{{ Form::open(array('route' => 'generate', 'files' => true)) }}
{{ Form::radio('myType', '1', true); }}
{{ Form::label('myType', '1'); }}
{{ Form::radio('myType', '2'); }}
{{ Form::label('myType', '2'); }}
{{ Form::radio('myType', '3'); }}
{{ Form::label('myType', '3'); }}
{{ Form::text('myName'); }}
{{ Form::file('uploadImage'); }}
{{ Form::submit('Go'); }}
{{ Form::close() }}
还有我的控制器:
$validator = Validator::make(Input::all(), array('uploadImage' => 'required|image', 'myName' => 'required'));
if ($validator->fails()){
return Redirect::back()->withErrors($validator);
}
我尝试过类似的事情:
return Redirect::back()->withErrors($validator)->with('nameValue', Input::get('myName'));
然后在视图中:
{{ Form::text('myName', $nameValue); }}
但是它仍然不起作用.任何帮助将不胜感激.
But it still doesn't work. Any help will be appreciated.
推荐答案
if ($validator->fails()){
return Redirect::back()->withErrors($validator);
}
更改为
if ($validator->fails()){
return Redirect::back()->withErrors($validator)->withInput();
}
您可以通过Input::old()
方法检索该值.
you can retreive the value by Input::old()
method.
您尝试过: return Redirect::back()->withErrors($validator)->with('nameValue', Input::get('myName'));
上面,您可以从Session
获取值.
above, you can get the value from Session
.
Session::get('nameValue')
这篇关于在Laravel 4中重定向回时保留表单值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文