簡體   English   中英

Laravel發布表單錯誤

[英]Laravel post form error

我第一次提交表單時遇到問題。

當我提交表格時,它不會發布路線,我也不知道為什么。

我的張貼路線是:

    Route::post('/app/add-new-db', function()
  {
    $rules = array(
          'name' => 'required|min:4',
          'file' => 'required'
    );

    $validator = Validator::make(Input::all(), $rules);
    if ($validator->fails()) {

      // get the error messages from the validator
      $messages = $validator->messages();

      // redirect our user back to the form with the errors from the validator
      return Redirect::to('app/add-new-db')
         ->withErrors($validator);

     }
     else
     {
        $name = Input::get('name');
        $fname = pathinfo(Input::file('file')->getClientOriginalName(), PATHINFO_FILENAME);
        $fext = Input::file('file')->getClientOriginalExtension();
        echo $fname.$fext;
        //Input::file('file')->move(base_path() . '/public/dbs/', $fname.$fext);

        /*
        DB::connection('mysql')->insert('insert into databases (name, logotipo) values (?, ?)',
         [$name, $fname.$fext]);
         */
       //return Redirect::to('app/settings/');
     }
  });

和我的HTML:

    <div class="mdl-cell mdl-cell--12-col content">
  {!! Form::open(['url'=>'app/add-new-db', 'files'=>true]) !!}
  <div class="mdl-grid no-verticall">
    <div class="mdl-cell mdl-cell--12-col">
      <h4>Adicionar Base de Dados</h4>
      <div class="divider"></div>
    </div>
    <div class="mdl-cell mdl-cell--6-col">
      <div class="form-group">
        {!! Form::label('name', 'Nome: ') !!}
        {!! Form::text('name', null, ['id'=> 'name', 'class' => 'form-control']) !!}
      </div>
      <div class="form-group">
        {!! Form::label('image', 'Logotipo:') !!}
        {!! Form::file('image', ['class'=>'form-control']) !!}
        @if ($errors->has('image'))
          <span class="error">{{ $errors->first('image') }}</span>
        @endIf
      </div>
      <div class="form-group">
        {!! Form::submit('Adicionar', ['id'=>'add-new-db', 'class'=>'btn btn-default']) !!}
        <p class="text-success"><?php echo Session::get('success'); ?></p>
      </div>
    </div>
  </div>
  {!! Form::close() !!}
</div>

我正在從一個jQuery get加載此:

    function addDB()
   {
     $( "#settings-new-db" ).click(function(e)
     {
       $.get('/app/add-new-db', function(response)
       {
          $('.content-settings').html("");
          $('.content-settings').html(response);
          componentHandler.upgradeDom();
       });
       e.preventDefault();
     });
   }

當我嘗試提交表單時,我在chrome的網絡控制台中找到302。

我以這種方式做表格,這是第一次發生。 有人可以幫助我嗎?

謝謝

修復圖像上傳字段的名稱屬性。 您在表單中將其稱為image ,但嘗試在控制器中將其作為file獲取。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM