表单提交,输入:all()不显示所有输入

时间:2015-03-05 09:21:55

标签: forms laravel

RESTful,当我提交表单并在Store方法中返回Input:all()时,我只得到几个输入而不是全部!!

有谁可以帮助我找出原因?

并告诉我,如果我一直使用Ajax提交表单,请举例说明!

在Controller中存储方法:

/**
 * Store a newly created HOTEL in DB.
 *
 * @return Response
 */
public function store(/*AddNewHotelRequest $addNewHotelRequest*/)
{

    if(Request::ajax()) {
        if ( Session::token() !== Input::get( '_token' ) ) {
            return Response::json( array(
                'msg' => 'Unauthorized attempt to create setting'
            ) );
        }
        $input = Request::all();

        $response = [
            'status' => 'success',
            'input' => $input,
            'msg' => 'Hotel created successfully',
        ];

        return Response::json( $response );
    }
    // return Input::all(); //with Request::all() same output
}

从“创建新酒店”视图中填写表格

{!! Form::open([ 'data-remote' ,'method'=>'POST', 'action' => 'HotelsController@store', 'class' => 'panel form-horizontal','id'=>'hotelForm']) !!}
<input id="myToken" type="hidden" name="_token" value="{{ csrf_token() }}" />
<script> var _CSRT_token = "{{ csrf_token() }} " ;</script>
    <div class="panel-heading">
        <span class="panel-title">Adding New Hotel</span>
    </div>
    <div class="panel-body">

         <!-- / .form-group of Errors -->
         <div class="form-group">
             <div class="col-sm-12">
                 @include('errors.list')
             </div>
         </div>

        <!-- Hotel Name -->
        <div  class="form-group">
            <label for="hotel_name" class="col-sm-2 control-label">Hotel name *</label>
            <div class="col-sm-2">
                <input type="text" class="form-control" id="hotel_name" name="hotel_name" placeholder="Hotel name">
            </div>
            <p class="label label-warning label-tag">Name should be in English</p>
        </div>

          <!-- / .form-group of hotel_details -->
          <div class="form-group">
              <label for="hotel_details" class="col-sm-2 control-label">Hotel Details</label>
              <div class="col-sm-8">
                  <textarea class="form-control" id="hotel_details" placeholder="Short description, General information or Some Details about this Hotel" rows="3"></textarea>
              </div>
              <p class="label label-warning label-tag">Details should be in English</p>
          </div>


        <!-- Hotel website -->
        <div class="form-group">
            <label for="hotel_website" class="col-sm-2 control-label">Website *</label>
            <div class="col-sm-2">
                <input type="text" class="form-control" id="hotel_website" name="hotel_website" placeholder="http://">
            </div>
        </div>

         <!-- / .form-group of rank -->
         <div class="form-group">
             <label for="rank" class="col-sm-2 control-label">Rank</label>
             <div class="col-sm-1">
                 <input type="text" class="form-control" id="rank" placeholder="Boutique or 4">
             </div>
         </div>

        <div class="panel colourable">
            <div class="panel-body">Prices</div>

             <!-- / .form-group of single_price -->
             <div class="form-group">
                 <label for="single_price" class="col-sm-2 control-label">Single price</label>
                 <div class="input-group col-sm-1">
                     <span class="input-group-addon">€</span>
                     <input type="text" class="form-control room-price-group" id="single_price">
                     <span class="input-group-addon">.00</span>
                 </div>
             </div>
             <!-- / .form-group of double_price -->
             <div class="form-group">
                 <label for="double_price" class="col-sm-2 control-label">Double price</label>
                 <div class="input-group col-sm-1">
                     <span class="input-group-addon">€</span>
                     <input type="text" class="form-control room-price-group" id="double_price">
                     <span class="input-group-addon">.00</span>
                 </div>
             </div>
             <!-- / .form-group of extra_bed_price -->
             <div class="form-group">
                 <label for="extra_bed_price" class="col-sm-2 control-label">Extra Bed price</label>
                 <div class="input-group col-sm-1">
                     <span class="input-group-addon">€</span>
                     <input type="text" class="form-control" id="extra_bed_price">
                     <span class="input-group-addon">.00</span>
                 </div>
             </div>
        </div>


        <div class="form-group">
            <label for="facilities" class="col-sm-2 control-label">Facilities *</label>
            <div class="col-sm-10">
                <select id="facilities" class="col-sm-8 form-controljs-example-basic-multiple" name="facilities"  multiple="multiple">
                    <optgroup label="Free">
                        @foreach($facilities as $facility)
                            @if(!$facility->is_surcharge)
                                <option class="" value="{{ $facility->id }}">{{ $facility->name }}</option>
                            @endif
                        @endforeach
                    </optgroup>
                    <optgroup label="Surcharge">
                        @foreach($facilities as $facility)
                            @if($facility->is_surcharge)
                                <option value="{{ $facility->id }}">{{ $facility->name }}</option>
                            @endif
                        @endforeach
                    </optgroup>
                </select>
            </div>
        </div>



        <div class="panel colourable">
            <div class="panel-body">Address</div>

            <!-- / .form-group of Country -->
            <div class="form-group">
                <label for="country" class="col-sm-2 control-label">Country *</label>
                <div class="col-sm-2">
                    <select id="country" class="form-control" name="country" >
                        <option></option>
                        @foreach($countries as $country)
                        <option value="{{ $country->id }}" phone_code="{{ $country->phone_code }}" >{{ $country->name }}</option>
                        @endforeach
                    </select>
                    <p  class="help-block helperQuote">Begin by choosing your country.</p>
                </div>
            </div>

            <!-- / .form-group of Region -->
            <div class="form-group">

                <label for="region" class="col-sm-2 control-label">Region *</label>
                <div class="col-sm-2">
                    <select id="region" class="form-control" name="region">

                    </select>
                </div>
            </div>
            <!-- / .form-group of city -->
            <div class="form-group">
                <label for="city" class="col-sm-2 control-label">City *</label>
                <div class="col-sm-2">
                    <select id="city" class="form-control" name="city">

                    </select>
                </div>
            </div>
            <!-- / .form-group of rank -->
            <div class="form-group">
                <label for="zip" class="col-sm-2 control-label">Zip Code</label>
                <div class="col-sm-1">
                    <input type="text" class="form-control" id="zip" placeholder="34600">
                </div>
            </div>

            <!-- / .form-group of city -->
            <div class="form-group">
                <label for="address" class="col-sm-2 control-label">Hotel Address *</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="address" placeholder="Street name, number of building floor ...etc">
                </div>
                {{--<p class="label label-warning label-tag">Address should be in English</p>--}}
            </div>

            <!-- / .form-group of map -->
            {{--GOOGLE MAPS--}}
            <div class="form-group">
                <label for="map" class="col-sm-2 control-label">Location *</label>
                {{--<a href="#" id="initMap" class="btn" onclick="initializeMap();return false;">Initialize Map</a>--}}
                <div class="col-sm-9">
                    <div id="map-canvas" class="" style="width: 100%; height: 350px !important;">
                    </div>
                    <p id="markerPosition" class="help-block"><i>Drag the pin to the position of the hotel </i></p>
                    <p id="lat" class="help-block">Latitude: 41.0694</p>
                    <p id="lng" class="help-block">Longitude: 29.0043</p>
                    <input  id="latitude" type="hidden" value="37.7577">
                    <input  id="longitude" type="hidden" value="-122.4376">

                </div>
            </div>

        </div> <!-- End of Address Panel -->



        <!-- Hotel tel -->
        <div class="form-group">
            <label for="country_code" class="col-sm-2 control-label">Country Code *</label>
            <div class="col-sm-1">
                <input type="text" class="form-control" id="country_code" name="country_code" placeholder="+90">
            </div>
            <label for="country_code" class="col-sm-1 control-label">Phone *</label>
            <div class="col-sm-2">
                <input type="text" class="form-control" id="phone" name="phone" placeholder="(___) ___-____">
            </div>
            <label for="extension" class="col-sm-1 control-label">Extension</label>
            <div class="col-sm-1">
                <input type="text" class="form-control" id="extension" name="extension" placeholder="3">
            </div>
        </div>

        <ht/>
         <!-- / .form-group of status -->
         <div class="form-group">
             <label for="status" class="col-sm-2 control-label">Status *</label>
             <div class="col-sm-2">
                 <select id="status" class="form-control" name="status"   >
                     <option value="0">Suspended</option>
                     <option value="1" selected>Draft</option>
                     <option value="2">Published</option>
                 </select>
                 <p  class="help-block helperQuote"><strong>Suspended:</strong>Trash,<strong>Draft:</strong>Default,<strong>Published:Online</strong></p>
             </div>
             <p class="label label-warning label-tag">Only Published Hotels will be online!</p>
         </div>

        {{--@if (Auth::user()->isAdmin())--}}
         <!-- / .form-group of publisher -->
         <div class="form-group">
             <label for="publisher" class="col-sm-2 control-label">Publisher *</label>
             <div class="col-sm-2">
                 <select id="publisher" class="form-control" name="publisher" >
                     @foreach($publishers as $publisher)
                         <option value="{{ $publisher->id }}">{{ $publisher->name }} ({{$publisher->type}}) </option>
                     @endforeach
                 </select>
             </div>
         </div>
        {{--@endif--}}




        <div class="form-group" style="margin-bottom: 0;">
            <div class="col-sm-offset-2 col-sm-1">
                <button type="submit" class="btn btn-lg btn-primary btn-flat"><span class="btn-label icon fa fa-plus-circle"></span> Add Hotel</button>
            </div>
            <div id="loader" class="col-sm-1" style="display: none;"><img src="/assets/images/plugins/bootstrap-editable/loading.gif" alt="loading regions" /></div>
        </div> <!-- / .form-group -->

        </div>
{!! Form::Close() !!}

输出如下:

{"_token":"PWKknjx5S9u8m98ApGDXYKqaTyF7aFZDaye9uYPm","hotel_name":"City Loft","hotel_website":"http:\/\/www.cityloft.com.tr\/","facilities":"23","country":"6","region":"3344950","city":"783593","country_code":"+355","phone":"(123) 123-1231","extension":"3123","status":"1","publisher":"1"}

1 个答案:

答案 0 :(得分:4)

您忘了酒店详情和价格的名称属性,可能更多

<textarea class="form-control" **name="hotel_detail"** id="hotel_details" placeholder="Short description, General information or Some Details about this Hotel" rows="3"></textarea>