0

Following the restful design, an url, where I handle a search query, should look like this:

/car/search/Audi

and the /car/search should display the search form. I think the form should use GET method, but If I set the method to get (method="get"), it will redirect to /car/search/?query=Audi.

How can I define the form, so It will redirect to /controller/method/{variable} ?

Edit.: I am using PHP5.4, Laravel 4

szab.kel
  • 2,356
  • 5
  • 40
  • 74

1 Answers1

0

this is simpler**

Route::get('car', function(){
   echo Form::open(array('url' => 'car/search/', 'method' => 'get'));
   echo Form::text('search');
   echo Form::submit('Click Me!');
   echo Form::close();
});

try this it will take your to this url car/search?search=[entry]

Route::get('car/search', function(){
return Input::get('search');
});

another route to catch it! When you use Forms with GEt method it will always give you a querysting parameter. becuase its what get meant to. Unleas you wanna use ajax to send the form manuelly onSubmit! then your could have your route like cars/search/{param} but in this case it has to be cars/search/?search={params}

Oguzhan
  • 724
  • 6
  • 12
  • Yeah, but how would you tell the form, to forward the request to this url. `
    ` would redirect to car/search?inputname=value
    – szab.kel Aug 11 '14 at 11:40
  • You edited your answer, still: I am not asking how should I define routes. I would like to know, how can I tell the form, to redirect to the restful pattern. – szab.kel Aug 11 '14 at 11:43
  • Yes if you wait i am just completing my answer :)). – Oguzhan Aug 11 '14 at 11:45
  • I can't open the form with the input the user will type in. You say I should `Form::open('route' => array('route.name', $USER's SEARCH INPUT));` It won't work. – szab.kel Aug 11 '14 at 11:58
  • So, basically, I can't do what I want. Only with ajax, but that way, the url won't change (/car/search containts the form, sends an ajax request to /car/search/xy, but the user's url will be the same, /car/search url and after searching, he/she can't link it to others :(). – szab.kel Aug 11 '14 at 13:59
  • basicaly what you need is an input and a button when you click button it will take the input value and redirect your page to /car/search/xy check out jquery you can easily do it in jquery – Oguzhan Aug 11 '14 at 14:08
  • Yeah, true. A button should just redirect to the url. Hmm – szab.kel Aug 11 '14 at 14:12