views:

28

answers:

1

Hello gurus!

i've picked up zend framework and being playing with it, and here is a situation i'll like to achieve.
i have default and user modules, user has a different layout user_layout that i load in predispatch of NovelsController of user modules.i have a small form in the user_layout that post dates (from and to ) to showAction of NovelsController.

here is the code

<!-- the form inside user_layout -->
<form method="get" action="/user/novels/show">
   <table class="font">
      <tr>
          <td> <label for="to">From:</label></td>
          <td class="simple_margin_left"><input type="text" id="from" name="from" size="12"/></td>
      </tr>
      <tr>
         <td> <label for="to">To:</label></td>
         <td class="simple_margin_left"><input type="text" id="to" name="to" size="12" /></td>
      </tr>
      <tr>
         <td> </td>
         <td></td>
      </tr>
      <tr>

          <td colspan="2" align="center"><button type="submit" style="padding-left:10px; padding-right:10px; margin-left:0px" class="classy">Check</button> </td>
      </tr>
   </table>

</form>

I use the following to

$input = new Zend_Filter_Input($filters, $validators);
$input->setData($this->getRequest()->getPost());

So far everything works fine i now want to enable pagination to the show.phtml.so i change the form action to get and defined route in my application.ini like so

resources.router.routes.user-show.route = /user/novels/show/:page/:from/:to
resources.router.routes.user-show.defaults.controller = novels
resources.router.routes.user-show.defaults.module = user
resources.router.routes.user-show.defaults.action = show
resources.router.routes.user-show.defaults.page = 1
resources.router.routes.user-show.defaults.from = ""
resources.router.routes.user-show.defaults.to = ""

how can i make the form action follow that rule, because up to now it's just a normal query string with question mark and variable=value.

How can i achieve that?thanks for reading this.

+1  A: 

This can't be done with ZF (and isn't worth doing) because of the way the browser works.

When a GET form is submit, in any language, the browser will build the query string as key-value pairs and append it to the URL specified in the action.

If you insist on all urls being 'pretty' you have a few options:

  • write code to redirect to a formatted address
  • use rewrite rules to redirect (Apache mod_rewrite)
  • use JavaScript to hijack the form's onsubmit method (won't work for users without JavaScript)
David Caunt
i use javascript location.replace method to perform a redirect and pass values to it.thanks for answering.
black sensei
Happy to help - I had this question myself once :)
David Caunt