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

makapaka's avatar

Can you use text input values in href link without JS

Sorry noob question - I have input values I want to use in the href which links to controller action - can it be done inline without javascript ?

Ie

 <div><input id="time1" type="text" value="15"></div>
 <a href="/round/{time1}/{15}">Show Times</a>

So /round/time1/{value} would come from whatever value entered into input time1 ?

Thanks!

0 likes
6 replies
click's avatar

No that is impossible without JS.

Maybe if you explain what you want to achieve we could suggest another solution.

I don't know what you are trying to achieve but you could achieve something equal with a GET form like this:

<form method="GET" action="/round/cup">
  <input type="" value="15" type="text" name="time1">
  <button type="submit">Show Times</button>
</form>

If you now click on 'show times' you will be directed to round/cup?time1=15

makapaka's avatar

@click essentially all I'm trying to do is call the controller with those input text values as params. Was just trying to avoid doing it in JS.

jlrdw's avatar

Just use your input and post the Form, I'm not getting why you need the href.

makapaka's avatar

@click @jlrdw how does the query work if I have two inputs ?

<input type="" value="15" type="text" name="time1">
<input type="" value="20" type="text" name="time2">

Can I not get the route to be in the form /round/time1/15/time2/20 ? Also, how does the controller access these params?

click's avatar

This is basic 'form handling' in a web application. You should be able to figure this out with some google search.

If you have multiple forms you can retrieve the values of the form inputs in your controller with

request()->post('time1');
request()->post('time2');

There are many tutorials about this subject. If you search on 'Laravel form handling' or something similar on Google you will find full examples that should get you started.

This is one of them: https://www.easylaravelbook.com/blog/creating-a-contact-form-in-laravel-5-using-the-form-request-feature/

They only use some form classes to build the form fields but that is not necessary.

jlrdw's avatar

And a follow-up anyone coming to laravel should be more than well versed in the basics of form handling.

Laravel should not be for someone new to programming rather a year or two after they are well-versed in PHP CSS HTML and JavaScript. Or at least 6 months of some basics.

Just my two cents and opinion.

Please or to participate in this conversation.