Edi
Edi

Reputation: 1

laravel 7 - unable to pass input parameter to form action for searching purpose

how i can pass input value form action and replace number 5? the below works if i put numbers only, then it pass it to route then controller:

<!--Search to mysql  -->
<form  action="{{ route('propertyname.show', 5)}}" method="GET" role="search">
    @csrf
      <Label for="id">search:</Lebal>
      <input type="text" id='id' name="id" placeholder="Search plzz">
      <input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
      <input type="submit" name="submit" value="Serach"> 
  </form>  

Route::get('/property_name/{id}','RsmsController@show')->name('propertyname.show');

the above works if I typed number 5 manually which I don't want, I want it to read\input from FORM TEXT and fired when clicking on the form button to send the value to the controller. http://127.0.0.1:8000/property_name/5 enter image description here

Upvotes: 0

Views: 47

Answers (1)

Digvijay
Digvijay

Reputation: 8967

You can take a look at simple jQuery on click/submit method.

$(function() {
    $("#myform").submit(function(e) {
        var actionUrl = "{{ url('/property_name/') }}" + $("#id").val();
        $(this).attr("action", actionUrl);
    });
});

Upvotes: 0

Related Questions