Support the ongoing development of Laravel.io →
Requests Forms

I have a form with 2 submit buttons;

<form class="form-horizontal" role="form" method="GET" action="{{ URL::to('split_form') }}">
{!! Form::hidden('postcode_id', $postcode_lookup['id']) !!}
<input class="btn btn-warning" type="submit" name="action" value="CSV" />
<input class="btn btn-info"    type="submit" name="action" value="Map"     />
</form>

Here is my routes.php;

Route::get('split_form', array(
    'before' => 'form_splitter',
    function()
    {
       print "three";
       Route::get('/export/csv', 'ExcelController@index');
       Route::get('/map/all', 'MapController@index');
    }
));

Here is my app/filters.php file;

<?php

Route::filter('form_splitter', function()
{
  if ( Input::get('action') === 'CSV' )
  {
    Redirect::to('/export/csv');
    print "one";
  }
  elseif ( Input::get('action') === 'Map' )
  {
    Redirect::to('/map/all');
    print "two";
  }
});

I'm doing just a couple of "hello worlds" on the two controllers at the moment but all I get back from the browser is "three". Do I have to register filters.php somewhere?

Last updated 2 years ago.
0

yes. you should include your filters somewhere.

0

LOL! Ok, where?

0

its either on your composer.json

"files": ["app/filters.php"]

Or you can create a service provider and load(include) it from there.

http://stackoverflow.com/questions/28290332/best-practices-for-custom-helpers-on-laravel-5/28360186#28360186

0

Sign in to participate in this thread!

Eventy

Your banner here too?

mikelovely mikelovely Joined 26 Mar 2015

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.

© 2025 Laravel.io - All rights reserved.