dongyong2906 2017-02-01 06:00
浏览 46
已采纳

显示从一个页面到另一个页面的表单输入值

I have two (2) pages. One is a Create page and the other one is a Confirm page. Create page has a form and a "Proceed to Confirm" button which will redirect to Confirm page. Confirm page should display all the inputs from the Create page, then the user will be able to submit it right after once he/she has checked all the inputted values.

Controller:

public function create()
{
    return ('pages.create');    
}

public function confirmCreate()
{
    $value = Input::all();
    Session::flash('value', $value);
    return view('pages.confirm-create')->with('value', $value);
}

Routes:

Route::get('create', 'MyController@create')->name('create');

Route::post('confirm-create', 'MyController@confirmCreate')->name('confirm-create');

Route::put('store', 'MyController@store')->name('store');

Create page View:

{{ Form::open(array('url' => 'confirm-create',
                                'method' => 'POST', 
                                'class' => 'form-horizontal')) }}

    <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
      <label class="col-md-4 control-label required">Name</label>
      <div class="col-md-6">
        <input id="name" placeholder="Name" type="text" class="form-control" name="name" value="{{ old('name) }}" required autofocus>
        @if ($errors->has('name'))
        <span class="help-block">
          <strong>{{ $errors->first('name') }}</strong>
        </span>
        @endif
      </div>
    </div>

    <div class="form-group{{ $errors->has('contactNumber') ? ' has-error' : '' }}">
      <label class="col-md-4 control-label required">Contact Number</label>
      <div class="col-md-6">
        <input id="contactNumber" placeholder="Contact Number" type="text" class="form-control" name="contactNumber" value="{{ old('contactNumber) }}" required autofocus>
        @if ($errors->has('contactNumber'))
        <span class="help-block">
          <strong>{{ $errors->first('contactNumber') }}</strong>
        </span>
        @endif
      </div>
    </div>

    <div class="form-group">
      <div class="col-md-6 col-md-offset-6">
        <button type="submit" class="btn btn-primary">
          Proceed to Confirm
        </button>
      </div>
    </div>

{{ Form::close() }}

Confirm page View:

{{ Form::open(array('url' => 'pages',
                                'method' => 'POST', 
                                'class' => 'form-horizontal')) }}

    <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
      <label class="col-md-4 control-label required">Name</label>
      <div class="col-md-6">
        <label class="control-label">{{ old('name') }}</label>
        @if ($errors->has('name'))
        <span class="help-block">
          <strong>{{ $errors->first('name') }}</strong>
        </span>
        @endif
      </div>
    </div>

    <div class="form-group{{ $errors->has('contactNumber') ? ' has-error' : '' }}">
      <label class="col-md-4 control-label required">Contact Number</label>
      <div class="col-md-6">
        <label class="control-label">{{ old('contactNumber') }}</label>
        @if ($errors->has('contactNumber'))
        <span class="help-block">
          <strong>{{ $errors->first('contactNumber') }}</strong>
        </span>
        @endif
      </div>
    </div>

    <div class="form-group">
      <div class="col-md-6 col-md-offset-6">
        <button type="submit" class="btn btn-primary">
          Submit
        </button>
      </div>
    </div>

{{ Form::close() }}

I can't seem to display the data from my Create page (after clicking "Proceed to Confirm" button) to my Confirm page. How should my controller, routes, and view (both Create and Confirm pages) look like? Send help. Thanks!

  • 写回答

2条回答 默认 最新

  • duanhe4267 2017-02-01 06:49
    关注

    You pass value to pages.confirm-create view but don't use it.

    Substitute {{ old('contactNumber') }} with {{ $value['contactNumber'] }} or {{ $value['contactNumber'] }}.

    Using old() is good when you have validation, it gets value from previous request rather than from a value passed to a view.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错