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.
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']) !!}
In my routes.php I have:
Route::controller('offer', 'OfferController');
Thanks in advance
yes, multiple submit buttons can include in the html form. One simple example is given below.
Having multiple submit buttons and handling them through PHP is just a matter of checking the the name of the button with the corresponding value of the button using conditional statements. In this article I'll use both elseif ladder and switch case statement in PHP to handle multiple submit buttons in a form.
If you don't have any submit button it is acceptable after all it is an element of form tag and if it is not required you may not add it with in form . This will not broke any web standard.
you can use the same name and different value attribute for the submit buttons
// example:
{!! Form::submit( 'Save', ['class' => 'btn btn-default', 'name' => 'submitbutton', 'value' => 'save'])!!}
{!! Form::submit( 'Save draft', ['class' => 'btn btn-default', 'name' => 'submitbutton', 'value' => 'save-draft']) !!}
// Controller:
switch($request->submitbutton) {
case 'save':
//action save here
break;
case 'save-draft':
//action for save-draft here
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With