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

uccdev's avatar

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

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">
 </form>'

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

Route::get('/c/courseList/{pageNumber}', 'IndexController@searchByCourse')->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?

0 likes
2 replies
rawilk's avatar
rawilk
Best Answer
Level 47

Easiest way I can think of is to use JavaScript to update the value of the hidden input whenever your "sort" value changes.

1 like
Sti3bas's avatar

@uccdev

<input type="radio" name="myOtherInput" onchange="document.getElementsByName('sort')[0].value=this.value" value="x">

Please or to participate in this conversation.