5 months ago

How to make PHP form refer to a value on the same HTML page?

Posted 5 months ago by uccdev

In PHP Laravel, I have a page which deals with API endpoint data. Right now it paginates this data, which I've managed accordingly:

 <form action="courseList" method="get">
  <input type="hidden" name="pageNumber" value="2"> <!--where '2' is the next page''
  <input type="submit" name="Submit" value="Next Page">

This passes in a single pageNumber argument, which works fine for my URL routing:

Route::get('/c/courseList/{pageNumber}', '[email protected]')->name('courseList');

Which then starts with:

public function searchByCourse(Request $request) { ...

This gives $request a pageNumber value, and it works. That's great.

Now I want to be able to add a "Sort" value to $request. But the catch is that this value has to be defined outside of the form I'm using. It has to come from another HTML field in the page.

I'd like to put it in as a hidden value inside the form field I listed above, and have its value stored there. e.g:

 <input type="radio" name="myOtherInput" value="x">

 <form action="courseList" method="get">
     <input type="hidden" name="sort" value="nameOfHTMLFieldItem"> ...

I've tried researching this problem, but most results are about passing values from external pages, not dealing with the internal.

Is this possible? How might I do it?

Please sign in or create an account to participate in this conversation.