带有两个提交按钮的Laravel表单 [英] Laravel form with two submit button

查看:49
本文介绍了带有两个提交按钮的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.

这篇关于带有两个提交按钮的Laravel表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆