php - Laravel One Form Two Submit Buttons -
i have form view;
<form class="form-horizontal" role="form" method="get" action=""> @foreach($input $key => $value) @foreach($value $subkey => $subvalue) {!! form::hidden($key.'_'.$subkey, $subvalue) !!} @endforeach @endforeach {!! form::hidden('postcode_id', $postcode_lookup['id']) !!} <input class="btn btn-info" type="submit" name="action" value="map view" /> <input class="btn btn-warning" type="submit" name="action" value="csv download" /> </form>
i have routes.php code;
if ( input::get('action') === 'csv download' ) { route::get('/export/csv', 'excelcontroller@index'); } if ( input::get('action') === 'map view' ) { route::get('/map/all', 'mapcontroller@index'); }
if user clicks 1 button, want them excelcontroller called. if it's other, want mapcontroller called... 2 different controllers!
what should action
route be? @ moment stays on current page when click either.
the action route empty, directs current page. should route. example
<.. action="{{ url::to('split_form') }}" ..>
you attach filter route (in routes.php):
route::get('split_form', array('before' => 'form_splitter'));
and define filter (in filters.php)
route::filter('form_splitter', function() { if ( input::get('action') === 'csv download' ) { redirect::to('/export/csv'); } elseif ( input::get('action') === 'map view' ) { redirect::to('/map/all'); } });
and define actual routes (in routes.php)
route::get('/export/csv', 'excelcontroller@index'); route::get('/map/all', 'mapcontroller@index');
though answer angelo in blackbischop's second link work want, saving filter/redirect using javascript
Comments
Post a Comment