By default, web browsers submit GET forms using the ?foo=bar syntax. There's nothing that ZF nor PHP can do to change this, because it all happens on the client side. So the only way to get pretty URLs is to use Javascript to override the default behavior.
The only way to get this to work using server-side code is to perform a redirect, which is an expensive process, so I don't suggest it. Regarding a JS solution, you'll need to be sure that you implement this in a way that is consistent with how forms are normally submitted. For example, if your form has two inputs by the same name, only the value of the last input is submitted (it overwrites the previous ones). But if you use array notation, then you can have multiple values for the same name, and they will all be submitted and PHP will read them as an array. AFAIK this can be difficult to do with the ZF router because it doesn't turn multiple values into arrays. Also, if your form has multiple submit buttons, each with their own actions (like "post" versus "cancel" buttons) then you'll need to submit the value for the button that was clicked. And finally, supporting this may have an impact on your controllers. If you are using $this->_request->getQuery() to read the values, note that it only reads from $_GET (by default). So if you rewrite your URL using Javascript, you'll only be able to use $this->_request->getParam() because $_GET will be empty. With that being said, it's a lot of work for very little benefit. But if you have a simple form with only a few elements, then you may not run into any problems supporting it. -- *Hector Virgen* Sr. Web Developer Walt Disney Parks and Resorts Online http://www.virgentech.com On Wed, Jul 14, 2010 at 12:39 PM, Andrew Ballard <[email protected]> wrote: > On Wed, Jul 14, 2010 at 3:24 PM, David Mintz <[email protected]> wrote: > > > > > > On Wed, Jul 14, 2010 at 3:11 PM, Andrew Ballard <[email protected]> > wrote: > >> > >> On Wed, Jul 14, 2010 at 2:58 PM, David Mintz <[email protected]> > wrote: > >> > > >> > Having become addicted to pretty URLs, I am finding the ugly kind you > >> > get > >> > following submission of a GET form rather... ugly. Just wondering if > >> > anyone > >> > has any ideas about this, before I consider writing some Javascript to > >> > suppress the default event and location.href = > example.org/param1/value1 > >> > etc > >> > > >> > -- > >> > Support real health care reform: > >> > http://phimg.org/ > >> > > >> > -- > >> > David Mintz > >> > http://davidmintz.org/ > >> > > >> > > >> > > >> > >> That would be pretty simple to do. If you pursue it, you would need to > >> make sure your PHP code still correctly handles the page with the > >> regular GET parameters in case someone visiting your site has > >> Javascript blocked/disabled. In other words, the page would need to > >> respond the same to a request for either of these resources: > >> > >> example.org/?param1=value1 > >> > >> example.org/param1/value1 > >> > > > > > > ZF handles that for us transparently, doesn't it? That is, in a > controller > > $this->_getParam('param1') will return 'value1' either way. > > > > > > -- > > Support real health care reform: > > http://phimg.org/ > > > > -- > > David Mintz > > http://davidmintz.org/ > > > > > > > > Yes, I guess it does. :-) I'm so used to using getUserParams() and not > using query strings that I had forgotten that getParams() includes the > regular request parameters as well. > > Andrew >
