这是我保存表单数据的代码。
Route::any('test', function(){
if (Request::isMethod('post')){
//return Redirect::back()->withInput();
return Redirect::to('test2')->withInput();
}
else {
return View::make('home');
}
});
Route::get('test2', function(){
return var_dump(Input::all()); // Getting Empty Array here.
});我只需输入一个名字=‘电子邮件’,并发布它。当重定向到另一个页面时,它不会使用Redirect::to('test2')->withInput();转发输入
<form action="" method="post">
<input type="text" name="email" value="" placeholder="Your Email">
<input type="submit" value="Submit" />
</form>我很困惑,如何使用Input::flash()或Redirect::to('test2')->withInput();
发布于 2014-06-27 06:35:38
Exammple:
Route::any('test', function(){
if (Request::isMethod('post')){
Input::flash();
return Redirect::back();
// return Redirect::back()->withInput();
}
else {
if(Input::old('email'))return Input::old(); //::old is only accessible when we did ::flash() or ::withInput()
return View::make('home');
}
});若要检索错误等方面的表单数据,请使用
Input::old() 并且输入::old(),如果没有,将永远无法工作
Redirect::back()->withInput()或
Input::flash();
return Redirect::back();详细信息作为注释附在代码中。
发布于 2014-06-25 15:29:10
当您使用Redirect::to()->withInput()时,它所做的就是将Input::all()的当前状态放入会话变量中供以后访问(它不会重新提交输入或类似的内容)。因此,在新的重定向请求中,您不能使用Input:all()访问相同的输入(因为它没有重新发布),但是现在它在Input::old()下。就像一个flahs变量一样,它也只能用于一个请求,所以如果您想重新闪存它,您可能需要执行Session::reflash()或者您可能能够再次->withInput() (尽管我对它表示怀疑,因为新的Input::all()是空的)。
希望这是合理的。基本上,您的“test2”路径需要使用Input::old()。
尽管如此,如果您要将POST请求重定向到稍后通过Input::old()处理,则可能是在做一些不太正确的事情--这并不是这个构造的真正目的。当然,如果您只是在玩弄框架,那么您就可以随心所欲地做任何事情。
https://stackoverflow.com/questions/24401454
复制相似问题