Faced a problem, on the search page there were several GET-forms with page-by-page navigation, sorting and search query parameters.

The problem is that when you submit any of these forms, the previous GET value is erased. For example, the user chose “Camomile” (? Flower = romashka) in the search, and then moved to another page and the search query disappeared, only (? Page = 2) remained.

Actually, is there a way to handle GET parameters? Overwriting existing ones (for example, sortby = Up to sortby = down) and adding new ones to the request when received.

  • But is it not possible to organize a search through $_POST ? Much more convenient, and less work - Rosnowsky
  • one
    No, you can not, the user can not save the post as a link and then go back and scroll through a few more pages on your request. Besides, this does not solve the problem of navigation. - enhaster
  • Well, combine them into one form and the problem is solved. - hindmost
  • How can I combine inputs separated into different parts of a page into one form? Oo - enhaster
  • @enhaster is easy - you just need to wrap the entire page in <form> once. But I would not recommend doing so. - Pavel Mayorov

2 answers 2

Add to each of the forms the parameters that need to be saved, either as hidden fields - or as part of the action :

 <form method=get> <input type=hidden name=flower value=romashka> <button name=sortby value=up>По возрастанию</button> <button name=sortby value=down>По убыванию</button> </form> 
  • I am afraid that this method is unproductive. The search form consists of a heap of inputs with arrays, besides their number is generated by the user on the page ... - enhaster
  • @enhaster and there is no other way - Pavel Mayorov

In general, the most convenient option is to put Jquery functions on the navigation, which will clone the page values ​​and add the hidden input to the search form, and then send it.

  • Just do not forget that when changing the filtering parameters or sorting the page number is not necessary. - Pavel Mayorov