1
votes

I am having a problem with setAction in the zend form. I have a multi-page form and to all the subforms i have set the same action

$subForm->setAction('process')
        ->setMethod('post');

my forms are being rendered in index action, application controller, buyer module http://localhost/project/public/buyer/application but when i submit the forms url is redirected/posted to url : http://localhost/project/public/buyer/process (to a page that doesnot exist)

It seems to be working when I setup a virtual server on my machine but I cannot get it to work when working with localhost or when deployed in any other server.

I tried with whole of the url but it don't seem to be working either i.e. $subForm->setAction('buyer/applciation/process') or $subForm->setAction('application/process')

6

6 Answers

2
votes

I've always found it easiest to set the form's action attribute from the view using the Url helper. Try it like this

<?php echo $this->form->setAction($this->url(array(
    'action' => 'process'
))) ?>
1
votes

I found out what was wrong with my code, It seems that zend was treating my url :- http://localhost/project/public/buyer/application as buyer controller and application action i.e. since the action is index and it is not included in my url. what my piece of code $form->setAction('process'); would do was it would simply replace the 'application' with 'process' http://localhost/project/public/buyer/process assuming that that application was the action. If I am not wrong then that might be a bug or so it might seem.

I renamed my action index as form and now it seems to be working. Though I liked how @Phil had suggested. But just incase someone else woul

0
votes

Do you have apache setup with the rewrite rules that ZF requires?

http://framework.zend.com/manual/1.10/en/project-structure.rewrite.html

0
votes

When you did $subForm->setAction('process'), it is essentially setting a relative path to the url at /project/public/buyer/application which means it's going to assume that project, public and buyer are directories and process should be at the same level as application.

Try this:

$this->form->setAction('/application/process');

I'm not really sure what the proper url is, but I'd try using that URL with a leading / so that it's no longer relative.

0
votes

do

$subForm->setAction($this->getView()->url(array('action'=>'process','controller'=>'application','module'=>'buyer'),null,true))
        ->setMethod('post');
0
votes

it looks to me like the problem is that process is not an action in a controller. It looks more like a method or class being called. What you will see done most often in ZF is to set your form action to an action.

//set form action to a controller action where you can call process against the form.
$form->setAction('action')//or 'controller/action' or 'module/controller/action'

the ZF reference has a rather extensive discussion on how to do multi part forms