Search code examples
laravelget

how to fetch data from form's input and pass it into same form's action laravel


So my code looks like this:

<form method="get" action="{{URL::to('users', $_GET['username'])}}">
     <input type="text" name="username">
     <input class="but-submit"  type="submit" name="submit">
</form>

I want my link to look like users/anydata, so that I could use it to fetch info from database.

My controller look like this:

Route::resource('users', 'UsersController');

Solution

  • I hope this can help you.

    --Write a JavaScript function and update the URL

    <form name="mForm" method="get" onSubmit="formSubmitAction(this)">
    
    function formSubmitAction()
    {
    	var username = document.getElementsByName("username").value;
    	document.mForm.action = "http://yourURL.com/"+username; 
    	document.myForm.submit();
    }