I have a form in a php file as given below (I have designed it as a Table in my code but showing only the form here so that I can explain my current problem):
The following code is for Searching
echo '<form id="stat_form">
<input form="stat_form" type="text" name="search" placeholder="Enter search term" onfocus="this.placeholder = \'\'" onblur="this.placeholder = \'Enter search term\'">
<input form="stat_form" type="submit" value="Search" action="'.$_SERVER['PHP_SELF'].'">
</form>';
After some more operations, the following is added to the code for Sorting(used as the table headers) in which $title1 and $title2 are different from the corresponding Button values(Hence used < button> instead of < input>):
echo '<button form="stat_form" name="sort" value="Name" action="'.$_SERVER['PHP_SELF'].'">'.$title1.'</button>
<button form="stat_form" name="sort" value="Address" action="'.$_SERVER['PHP_SELF'].'">'.$title2.'</button>';
And finally after few more functions the following is added for Pagination. $prev_page, $curr_page and $next_page are calculated in my code:
echo '<button form="stat_form" name="page" value="'.$prev_page.'" action="'.$_SERVER['PHP_SELF'].'"'.($prev_page==$curr_page?" disabled":"").'>Prev</button>
<button disabled>'.$curr_page.'</button>
<button form="stat_form" name="page" value="'.$next_page.'" action="'.$_SERVER['PHP_SELF'].'"'.($next_page==$curr_page?" disabled":"").'>Next</button>';
Now my problem is(Assuming that I have already entered the Search string):
According to the code that I have explained above, I would like to send 3 different values from the form at all times: "search", "sort", and "page" How can I establish this?
Kindly do not suggest to use any library or external tool. Currently I wont be able to include any into my code.
Also since it is my first post in the forum, I am not sure if I have made my question clear. Kindly let me know so that I can explain further.
Thanks in advance.
I have been looking around for the solution for the whole day but not able to get a satisfactoy answer. Hence using a work around here. I will post it here in case it will help others:
The only modification was in the pagination. I have removed it from the form and used it as a normal link. The drawback will be that when I do a sort, the page value is reset. Since it does not affect my project. I am inclined to use this solution.
echo '<a href="'.$prev_page_url.'"><button class="buttons"'.($prev_page==$curr_page?" disabled":"").'>Prev</button></a>
<button disabled>'.$curr_page.'</button>
<a href="'.$next_page_url.'"><button class="buttons"'.($next_page==$curr_page?" disabled":"").'>Next</button></a>';
In the above code, $prev_page_url and $nextpage_url were calculated as
$_SERVER['PHP_SELF'].http_build_query(<search/sort/page parameters>)