Support the ongoing development of Laravel.io →
posted 10 years ago
Input Forms
Last updated 2 years ago.
0

I'd rather do the following

{{ Form::button('Edit', array('type' => 'button', 'class' => 'btn btn-default btn-primary btn-switch', 'data-type' => 'edit')) }}
{{ Form::button('Add', array('type' => 'button', 'class' => 'btn btn-default btn-success btn-switch', 'data-type' => 'add')) }}
{{ Form::hidden('btnSelected', Input::old('btnSelected'), array('id' => 'btnSelected')) }}

You'll need some jQuery here, to populate the #btnSelected hidden input with the type of button selected.

$('.btn-switch').on('click', function(){
    $('#btnSelected').empty().val($(this).attr('data-type'));
    $('#yourForm').submit();
});

Now, how this works..

First off, you have the two buttons, but not submit, just plain ol' buttons. As you can see, I added the data-type attribute in order to detect what button was pressed.

After a button is pressed, the #btnSelected input is populated with this data-type attr I previously mentioned, and then the form submit() event is triggered.

From your controller, you'll just have to do

Input::get('btnSelected');

This will return you the type of button that was pressed.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

svrdlic svrdlic Joined 26 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.