views:

116

answers:

2

Hi,

I have a form, created with Zend_Form, with method = GET used for searching records with elements as below:

[form] user name [input type="text" name="uname"] [input type="submit" value="Search" name="search"] [/form]

After form is submitted all the GET parameters along with submit button value are appearing in the url.

http://mysite.com/users/search?uname=abc&search=Search

How to avoid submit button value appearing in the url? is custom routing the solution ?

+1  A: 

In the controller that represents the form's action, redirect to another (or the same controller) only including the relevant params.

Pseudocode:

$params = $this->getRequest()->getParams();
if isset($params['search'])
  unset($params['search']);
  return $this->_helper->Redirector->setGotoSimple('thisAction', null, null, $params);

handle form here

This is basically the same idea as Post/Redirect/Get except that you want to modify the request (by unsetting a parameter) in between the different stages, instead of doing something persistent (the images on that Wiki-page shows inserting data into a database).

If I were you, I would leave it in. IMO it's not worth an extra request to the webserver.

chelmertz
I thought there may be some already existing code or functionality in the zend framework. thanks....
adithya
@adithya: You could always have a text link on the search results page saying "You've searched for <a href searchresults/dogs>dogs</a>" to keep some kind of functionality of a clean URL. But check Google for example, very ugly URL.
chelmertz
A: 

When a form gets submitted, all of its elements with their names and values become a part of a GET / POST - query.

So, if you don't want an element to appear in your GET - query, all you need to do is to create this element without a name. That's probably not the best approach, but since we're talking about the 'submit' element, I guess it doesn't matter that much.

Looking at Zend_View_Helper_FormSubmit helper, you can see that it's creating the 'submit' element and setting its name. So, the possible solution would be to create your own view helper and use it for rendering the 'submit' element instead of the default helper.

You can set a custom helper with

$element->setAttribs( array('helper' => 'My_Helper_FormSubmit') );
Vika