Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rei23's avatar
Level 1

Is there a way to put parameters from two forms on the same GET request?

I have a project where a collection is returned as search results. Then these results are filtered using a form that fires a get request. Now i want to put in another form to sort collection items by time posted, price, etc.. Does anyone know a way how i go about doing this?

0 likes
2 replies
Cronix's avatar

Why wouldn't that be a part of the same form?

WW's avatar

Not sure if I understood you correctly, but it seems like you have a page with certain results, and you would like to be able to sort them by different attributes (time, price, etc).

Basically, what you need to do is to send a request to the same page, but with added sorting options.

For example, let's say your page is http://www.mySite.com/myResults

Then, somewhere on your page, or right in the head of your table (if you have one), add a link:

<a href="/myResults?sortby=date">Sort by Date</a>

Now, in your controller where you handle index (or whatever function) you can use:

if (isset($_GET['sortby'])) {
    $sort = $_GET['sortby']; // or you can use request()->input('sortby');
    $results = MyModel::all()->orderBy($sort, 'desc')->get();
}

You may add as many parameters as you would like, for example:

<a href="/myResults?sortby=date&order=desc">Sort by Date</a>

Please or to participate in this conversation.