Laravel - 表单仅从刀片视图中的一个部分提交数据

时间:2017-08-10 22:27:16

标签: laravel laravel-5 blade

我正在处理的一个视图文件中包含两个部分,它们是侧边栏和内容部分。我遇到了一个相当混乱的问题,因为这两个部分都包含我想通过表单提交的数据。

由于某种原因,视图仅在内容部分呈现表单,并且不包括侧栏部分中的所有数据。最初我想打开内容部分顶部的表单,并在侧边栏部分的末尾关闭它可以工作。不幸的是情况并非如此,我不知所措。

我想知道是否有可能扩展表单,以便包含两个部分的数据?如何解决这个问题的任何建议将不胜感激!

@extends('main')

@section('title', 'Sign Up')

@section('content')
  {!! Form::open(['route' => 'signup.store', 'method' => 'post']) !!}
  <div class="panel-header"><span>{{ $visitor->username }}'s Profile</span></div>
  <div class="secondary-panel" align="center"><strong>Player Information</strong></div>
  <div class="xbs-border"></div>
  <div class="row_1g">
    <div class="body-content">
      <div class="col-md-6">
        <div class="form-group">
          {{ Form::label('first', 'First Name') }}
          {{ Form::text('first', $player->first, array('class' => 'form-control', 'placeholder' => 'First Name')) }}
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          {{ Form::label('last', 'Last Name') }}
          {{ Form::text('last', $player->last, array('class' => 'form-control', 'placeholder' => 'Last Name')) }}
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          {{ Form::label('number', 'Number') }}
          {{ Form::selectRange('number', 0, 99, $player->num, array('class' => 'form-control')) }}
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          {{ Form::label('birthday', 'Birthday') }}
          {{ Form::date('birthday', $player->birthday, array('class' => 'form-control')) }}
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          {{ Form::label('city', 'City') }}
          {{ Form::text('city', $player->city, array('class' => 'form-control', 'placeholder' => 'City')) }}
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          {{ Form::label('state_province', 'State/Province') }}
          {{ Form::select('state_province',['United States' => ['' => 'State/Province', 'AL'=>'Alabama','AK'=>'Alaska','AZ'=>'Arizona','AR'=>'Arkansas','CA'=>'California','CO'=>'Colorado','CT'=>'Connecticut','DE'=>'Delaware','DC'=>'District of Columbia','FL'=>'Florida','GA'=>'Georgia','HI'=>'Hawaii','ID'=>'Idaho','IL'=>'Illinois','IN'=>'Indiana','IA'=>'Iowa','KS'=>'Kansas','KY'=>'Kentucky','LA'=>'Louisiana','ME'=>'Maine','MD'=>'Maryland','MA'=>'Massachusetts','MI'=>'Michigan','MN'=>'Minnesota','MS'=>'Mississippi','MO'=>'Missouri','MT'=>'Montana','NE'=>'Nebraska','NV'=>'Nevada','NH'=>'New Hampshire','NJ'=>'New Jersey','NM'=>'New Mexico','NY'=>'New York','NC'=>'North Carolina','ND'=>'North Dakota','OH'=>'Ohio','OK'=>'Oklahoma','OR'=>'Oregon','PA'=>'Pennsylvania','RI'=>'Rhode Island','SC'=>'South Carolina','SD'=>'South Dakota','TN'=>'Tennessee','TX'=>'Texas','UT'=>'Utah','VT'=>'Vermont','VA'=>'Virginia','WA'=>'Washington','WV'=>'West Virginia','WI'=>'Wisconsin','WY'=>'Wyoming',], 'Canada' => ['AB' => 'Alberta', 'BC' => 'British Columbia', 'MB' => 'Manitoba', 'NB' => 'New Brunswick', 'NL' => 'Newfoundland', 'NS' => 'Nova Scotia', 'NT' => 'Northwest Territories', 'NU' => 'Nunavut', 'ON' => 'Ontario', 'PE' => 'Prince Edward Island', 'QC' => 'Quebec', 'SK' => 'Saskatchewan', 'YT' => 'Yukon']], $player->state_province, array('class' => 'form-control')) }}
        </div>
      </div>
    </div>
    <div class="row_1f" style="text-align:center;border-top:1px solid #ddd;">
      <div class="body-content">
        <strong>Player name falls under the site terms and conditions.</strong>
      </div>
    </div>
  </div>

  <div class="panel-header"><span>Additional Information</span></div>
  <div class="secondary-panel" align="center"><strong>Player Availability</strong></div>
  <div class="xbs-border"></div>
  <div class="row_1g">
    <div class="body-content">
      <div class="col-md-6">
        <div class="form-group">
          {{ Form::label('time', 'Preferred Time (EST)') }}
          {{ Form::select('time', ['9' => '9:00 PM', '10' => '10:00 PM', '11' => '11:00 PM'], $player->time, array('class' => 'form-control')) }}
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          {{ Form::label('commitment', 'League Commitment') }}
          {{ Form::select('commitment', ['0' => 'Part-Time', '1' => 'Full-Time',], $player->commitment, array('class' => 'form-control')) }}
        </div>
      </div>
      <div class="col-md-12">
        <div class="form-group">
          {{ Form::label('available_extra', 'Availability Extra') }}
          {{ Form::textarea('available_extra', $player->available_extra, array('class' => 'form-control', 'placeholder' => 'Any additional information that you would like to add.')) }}
        </div>
      </div>
    </div>
  </div>
  <div class="row_1g">
    <div class="body-content">
      <div class="form-group" align="center">
        {!! Form::hidden('player_id', $visitor->user_id) !!}
        {{ Form::submit('Submit Registration', array('class' => 'btn xbs-button')) }}
      </div>
    </div>
  </div>
  <div class="row_1f" style="border-top:1px solid #ddd;">
    <div class="body-content">
      <ul style="margin-bottom:0;">
        <li><strong>Part-Time Player</strong> - At least two games per week.</li>
        <li><strong>Full-Time Player</strong> - Anything over two games games per week.</li>
      </ul>
    </div>
  </div>
@endsection

@section('sidebar')
  <div class="panel-header"><span>Position Preferences</span></div>
  <div class="secondary-panel" align="center"><strong>Position Breakdown</strong></div>
  <div class="xbs-border"></div>
  <div class="col-md-12 no-padding">
    <div class="row_1g">
      <div class="body-content">
        <div class="col-xs-12">
          <div class="form-group">
            {{ Form::label('pos_c', 'Center') }}
            {{ Form::select('pos_c', ['0' => 'Never', '1' => 'Rarely', '2' => 'Occasional', '3' => 'Preferred'], null, array('class' => 'form-control')) }}
          </div>
          <div class="form-group">
            {{ Form::label('pos_lw', 'Left Wing') }}
            {{ Form::select('pos_lw', ['0' => 'Never', '1' => 'Rarely', '2' => 'Occasional', '3' => 'Preferred'], null, array('class' => 'form-control')) }}
          </div>
          <div class="form-group">
            {{ Form::label('pos_rw', 'Right Wing') }}
            {{ Form::select('pos_rw', ['0' => 'Never', '1' => 'Rarely', '2' => 'Occasional', '3' => 'Preferred'], null, array('class' => 'form-control')) }}
          </div>
          <div class="form-group">
            {{ Form::label('pos_ld', 'Left Defense') }}
            {{ Form::select('pos_ld', ['0' => 'Never', '1' => 'Rarely', '2' => 'Occasional', '3' => 'Preferred'], null, array('class' => 'form-control')) }}
          </div>
          <div class="form-group">
            {{ Form::label('pos_rd', 'Right Defense') }}
            {{ Form::select('pos_rd', ['0' => 'Never', '1' => 'Rarely', '2' => 'Occasional', '3' => 'Preferred'], null, array('class' => 'form-control')) }}
          </div>
          <div class="form-group">
            {{ Form::label('pos_g', 'Goalie') }}
            {{ Form::select('pos_g', ['0' => 'Never', '1' => 'Rarely', '2' => 'Occasional', '3' => 'Preferred'], null, array('class' => 'form-control')) }}
          </div>
        </div>
      </div>
    </div>
    <div class="row_1f" style="border-top:1px solid #ddd;">
      <div class="body-content">
        <ul style="margin-bottom:0;">
          <li><strong>Never</strong> - 0 games per season.</li>
          <li><strong>Rarely</strong> - up to 10 games per season.</li>
          <li><strong>Occasional</strong> - 10 to 20 games per season.</li>
          <li><strong>Preferred</strong> - Any amount of games.</li>
        </ul>
      </div>
    </div>
  </div>
  {!! Form::close() !!}
@endsection

Main.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    @include('partials._header')
    @yield('stylesheets')
</head>

<body>

  @include('partials._navigation')

  <div class="container">
    <div class="col-md-12" style="padding:0;margin-top:20px;">
      @include('partials._messages')
    </div>
    <div class="col-md-4" style="padding-left:0;">
      @yield('sidebar')
    </div>
    <div class="col-md-8" style="padding-right:0;">
      @yield('content')
    </div>
  </div>

  @include('partials._footer')

  @include('partials._javascript')

  @yield('scripts')

1 个答案:

答案 0 :(得分:0)

问题出在您的main.blade.php文件中。

此标记将导致浏览器尝试修复您的表单,因为开始和结束表单元素不共享同一个父级。

<div class="col-md-4" style="padding-left:0;">
    @yield('sidebar')
</div>
<div class="col-md-8" style="padding-right:0;">
    @yield('content')
</div>

这很可能会导致内容部分中的表单,而侧栏部分中没有任何表单。例如:

<div class="col-md-4" style="padding-left:0;">
    <form>
        ...
    </form>
</div>
<div class="col-md-8" style="padding-right:0;">
    ...
</div>

您需要使用表单元素包装列,或将列div移动到您的部分中。

@section('content')
    {!! Form::open(['route' => 'signup.store', 'method' => 'post']) !!}
        <div class="col-md-8" style="padding-right:0;">
            ...
        </div>
@endsection

@section('sidebar')
        <div class="col-md-4" style="padding-left:0;">
            ...
        </div>
    {!! Form::close() !!}
@endsection