带有两个提交按钮的Laravel表单

问题描述:

我需要两个提交按钮来更新表单,

I need two submit button for my update form,

当前,当我点击提交"时,它保存了我的数据并重定向到另一个页面,我可以在其中编辑多张图像(所以我的表单就像两步函数一样)

Currently when I hit submit it saves my data and redirect me another page where i can edit my multiple images (so my form is like two step function)

我想添加另一个按钮以仅保存我的数据并返回索引页面(跳过第二步)

I want to add another button in order to just save my data and return me to index page (skip second step)

最后的结果将是我的编辑表单,带有两个按钮

Last result will be my edit form with two button

  1. 按钮1保存数据并返回到下一个表单以编辑图像
  2. 按钮2保存数据并返回索引页面

代码

控制器功能

public function update(Request $request, $id)
    {
      // validation and....

      $product->save();

      // this is my current button action (redirect to second step)
      return redirect()->route('editmultiimages',
          $product->id)->with('success',
          'Product, '. $product->title.' updated, now you can edit images.');

     // need second button action here
}

刀片表单

{{ Form::model($product, array('route' => array('products.update', $product->id), 'method' => 'PUT', 'files' => true)) }}

// my inputs

// my current button (saves data and goes to next step)
{{ Form::submit('Edit Images', array('class' => 'btn btn-success')) }}

{{Form::close()}}

有什么主意吗?

已解决

刀片表单

{{ Form::submit('Edit Images', array('class' => 'btn btn-info', 'name' => 'submitbutton')) }}
{{ Form::submit('Finish', array('class' => 'btn btn-success', 'name' => 'submitbutton')) }}

控制器

switch ($request->submitbutton) {
        case 'Edit Images':
            return redirect()->route('editmultiimages', $product->id)->with('success', 'Product, '. $product->title.' updated, now you can edit images.');
            break;

        case 'Finish':
            Session::flash('success', 'Product, '. $product->title.' updated successfully.');
            return redirect()->route('products.index', $product->id);
            break;
}

希望它可以帮助其他人.

Hope it help others.