Laravel 5.1一表二提交按钮 [英] Laravel 5.1 one form two submit buttons

查看:91
本文介绍了Laravel 5.1一表二提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5.1,我想用两个提交按钮(保存和保存草稿)制作一个表单.

I am using Laravel 5.1, and I would like to make a form with two submit buttons - Save and Save draft.

但是,当我发布表单时,除了提交值之外,我具有所有字段.

But when I post my form I have all the fields except the submit value.

我已经了解到,通过ajax发送表单时,Laravel不会在POST中放置提交"按钮的值,所以请您帮我怎么做?

I have read that Laravel won't put the submit button value in the POST when the form was sent via ajax, so could you please help me how to do this?

我尝试了一些如下代码:

I have tried some code as below:

{!! Form::open(['url' => 'offer/create', 'method' => 'post', 'id' => 'offer-create']) !!}

....
here are my fields
....

{!! Form::submit( 'Save', ['class' => 'btn btn-default', 'name' => 'save']) !!}

{!! Form::submit( 'Save draft', ['class' => 'btn btn-default', 'name' => 'save-draft']) !!}

在我的route.php中,我有:

In my routes.php I have:

Route::controller('offer', 'OfferController');

预先感谢

推荐答案

您可以为提交按钮使用相同的名称和不同的值属性

you can use the same name and different value attribute for the submit buttons

//示例:

{!! Form::submit( 'Save', ['class' => 'btn btn-default', 'name' => 'submitbutton', 'value' => 'save'])!!}

{!! Form::submit( 'Save draft', ['class' => 'btn btn-default', 'name' => 'submitbutton', 'value' => 'save-draft']) !!}

//控制器:

switch($request->submitbutton) {

    case 'save': 
        //action save here
    break;

    case 'save-draft': 
        //action for save-draft here
    break;
}

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

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