0

I am implementing a search an sending a search form to an action. Everything is working as expected but the url after the submit isn't very friendly and contain undesirable information. It is showing the whole request query array as a query string. I have a form with a fieldset element named 'album-search'.

Here is the url I am getting right now:

http://hostname/music_organizer/public/albums/page/1?album-search[term]=art&csrf=12b6065ab7ea428f02ad36a9cc363752-d96a14c1c7f1f2961112014a1e200e03&search=Search

Here is the url i am want to get:

 http://hostname/music_organizer/public/albums/page/1?term=art

I have tried to set the query string in the action like this:

 public function searchAction(){
    //code
    $this->getRequest()->getQuery()->set('term', $term);
    //code
    return $viewModel;
}

but no luck, Thanks in advance

Frank
  • 49
  • 7

1 Answers1

0

I thought your current rendering form should be like this

<form method="get" action="...">
 <input name="term">
 <input type="hidden" name="csrf" value="...">
 <input type="submit" name="" value="Search">
<form>

Remove Submit Button:
Don't specify the submit button name while creating it
Remove CSRF element
If you don't required csrf element in querystring then remove it from your view page. but this csrf tag is very useful to avoid cross-site request forgery attacks.

--SJ

codeninja.sj
  • 3,452
  • 1
  • 20
  • 37
  • That would solve my problem now but what happend when my search become into an advanced search and It neccessary to use the fielset and forms objects? – Frank Oct 09 '14 at 22:25
  • @Frank, Sorry, i am not familiar with fieldset. I suggest to create it as a new question. – codeninja.sj Oct 11 '14 at 10:27