Chvanikoff Chvanikoff - 9 months ago 46
PHP Question

Setting action parameter to form in Zend

Im using "Zend form". What should I do to get correct "action" parameter in my FORM tag?

For example, the form Form_Search used in SearchController in indexAction. Where and how should I set the action parameter to form to make it "/my/app/directory/search/index"?

Update: "action" parameter should be the same as the form will assume if not set. I just need the param in FORM to simplify JS coding.


You can use setAction method of Zend_Form, e.g.:


Hope this is what you are looking for.

EDIT: You can retrieve many info about the request, in an action, using $this->getRequest() method that returns an instance of Zend_Controller_Request_Http. For example, if to get basePath and everything between the BaseUrl and QueryString you can do:

    $infoPath = $this->getRequest()->getPathInfo();
    $basePath = $this->getRequest()->getBaseUrl();

    $yourForm->setAction($basePath . $infoPath);

Zend_Controller_Request_Http has other methods that might be useful to you.