0

I have a simple ordering form in the app I'm developing:

{{ Form::open(array('route' => 'get.index', 'method' => 'get')) }}
                {{ Form::label('order', 'Order by') }}
                {{ Form::select('order' , array('firstname' => 'First Name', 'lastname' => 'Last Name', 'state' => 'State')) }}
                {{ Form::submit('Order results') }}
            {{ Form::close() }}

I'd like to append the order GET variable to be appended to variables in the query string if present, instead of overriding everything.

Is this possible somehow?

5
  • You could add the other GET variables as hidden fields to the form to re-send them. About what other variables are we talking about? Commented Feb 12, 2015 at 19:35
  • You can also set the action of the form (however you do that in "forms") to include the current query string ($_SERVER['QUERY_STRING']) and the browser will append the new values. Commented Feb 12, 2015 at 19:40
  • @JonathanKuhn Can I add an action alongsite the route option? I'd prefer having a route as an action. Commented Feb 12, 2015 at 19:51
  • @lukasgeiter there are a few other possible variables, 7 in total. Most of them are optional though, so it's not only the case that it has to be appended to 7 other variables. Commented Feb 12, 2015 at 19:52
  • I don't know, I don't use laravel. I was just suggesting it because that is how you would do it with a regular form. Commented Feb 12, 2015 at 20:00

1 Answer 1

2

As @JonathanKuhn mentioned, $_SERVER['QUERY_STRING'] holds the current query string. You can also retrieve it with Request::server('QUERY_STRING').

Then just use this as an action. You will have to use url but inside that you can again make use of the route() function for generating the url:

{{ Form::open(array('url' => route('get.index') . '?' . Request::server('QUERY_STRING'), 'method' => 'get')) }}
Sign up to request clarification or add additional context in comments.

2 Comments

I don't know laravel, but do you need to include the ? as part of the concatenated route? Because it won't be included with the query string.
@JonathanKuhn Yep thanks. I kind of had a feeling I was missing something ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.