在 Laravel 中通过确认页面和提交页面保留输入的正确方法是什么?

What is the correct way to persist input through a confirmation page and into a submission page in Laravel?

我一直在努力将我们的几个表单迁移到 Laravel,但是最后一步我不太确定如何进行。我有一个可以插入数据库的表单,但不是只有 2 个页面——表单和提交页面——我有 3 个页面:表单、确认页面和提交页面。

这是我目前拥有的:

路线:

Route::any('application/housing-form', array('as'=>'application.form', 'uses'=>'ApplicationController@form'));
Route::post('application/confirmation', array('as'=>'application.confirmation', 'uses'=>'ApplicationController@confirmation'));
Route::post('application/submit', array('as'=>'application.submit', 'uses'=>'ApplicationController@submit'));

应用程序控制器:

public function form()
{
    $application = new Application;
    return View::make('application/form')->with(array('application'=>$application));
}
public function confirmation()
{
    $input = Input::all();
    //More here?
    return View::make('application/confirmation')->with(array('input'=>$input));
}
public function submit() {
    $input = Input::all();
    DB::table('application')->insert(
        array(
            <field1>     => $input('field1')
            ...
             )
    );
    return View::make('application/submit');
}

观看次数:

//form
{{ Form::model($application, array('route'=>'application.confirmation')
    //inputs
    {{ Form::submit('Continue') }}
{{ Form::close() }}

//confirmation
{{ Form::open(array('route'=>'application.form') }}
    {{ Form::submit('Back to my information') }}
{{ Form::close() }}
{{ Form::open(array('route'=>'application.submit') }}
    {{ Form::submit('Submit') }}
{{ Form::close() }}

//submission
<p>Thank you for your submission!</p>

我不确定的是如何将表单中的数据通过确认页面保存到提交页面。据我所知,我可以看到几个选项:

  1. 刷新所有输入
  2. 使用隐藏字段(或多个字段)发送信息
  3. 在确认页面中将信息插入数据库,然后使用信息的中间查询进行更新。

我很确定这将是第一个:刷新数据。但如果是这样,我不确定您实际上应该在哪里调用 Session::flash 或 Session::reflash。或者我需要执行多少次才能通过所有请求。如果您有任何关于如何处理或如何简化表格其余部分的建议,我们将不胜感激。

还有一个额外的注意事项是,此特定表单处理大量输入字段(大约 60 个)。这就是为什么我想避免将每个单独的字段请求到最低限度的部分原因。

我要做的是将输入闪烁到会话中以重新填充表单。这可以通过使用 Input::flash() 方法来实现,如下所示:

public function confirmation(){
    Input::flash(); //this will store the input to the session
    return View::make('application/confirmation');
}

然后在您的视图中,使用 Input::old() 方法从之前的请求中检索输入数据:

{{ Form::text('fieldname', Input::old('fieldname')) }}