Thanks Matthew, your answer helped me a lot. Although I have another question. When I'm passing an array in _forward(), how can I get this array in action, were forward sent me. Thx
Matthew Weier O'Phinney-3 wrote: > > -- magrytos1 <[email protected]> wrote > (on Thursday, 16 July 2009, 02:19 AM -0700): >> I have an action like that: >> >> public function addAction() >> { >> $this->view->title = "Add Request"; >> $this->view->headTitle($this->view->title, 'PREPEND'); >> >> $form = new Form_Add(); >> $this->view->form = $form; >> >> if ($this->getRequest()->isPost()) { >> $formData = $this->_request->getPost(); >> if ($form->isValid($formData)) { >> $reqName = $form->getValue('requestName'); >> $type = $form->getValue('type'); >> $request = $form->getValue('request'); >> $requests = new Model_DbTable_Requests(); >> $requests->addRequest($reqName, $type, $request); >> $this->_forward('question'); >> } >> } >> } >> >> 1. Function addRequest adds the records to db. The problem is that after >> pushing my submit button, it goes to 'question', but it adds nothing to >> db. >> Why? > > That, I do not know. You'll need to step through the addRequest() method > of your model to debug it. > >> 2. What is all about this _forward function. I mean after call it, I'm in >> question view, but in my adress bar I still have public/index/add? I red >> ref >> guide, but I couldn't understand it :/ > > _forward() invokes another action *in the same request*. If you want the > address bar to change, you're wanting a redirect, and should use the > _redirect() method or the Redirector action helper. > >> 3. Question about submit: having 2 sub buttons I want them to send me to >> a >> different actions. I did something like this: >> >> if($form->yes->isChecked()){ >> $form->setAction('critere'); >> } >> else { $form->setAction('index'); } >> >> but my if-condition is always false > > The isChecked() method checks the value assigned to the button. You need > to first populate the form for it to work correctly: > > $form->populate($this->getRequest()->getPost()); > if ($form->yes->isChecked()) { > } else { > } > > Second, the form action is only going to affect the action attribute in > the form; it sounds like what you want to happen is to select which > controller action is invoked based on the button selected. If this is > the case, use _forward() or simply call the action directly: > $this->indexAction(). One note: _forward() will ensure the appropriate > view script is selected automatically but requires an additional > dispatch cycle, whereas calling the action directly will require you > update the action in the request object manually, or manually select the > view script to render. > > -- > Matthew Weier O'Phinney > Project Lead | [email protected] > Zend Framework | http://framework.zend.com/ > > -- View this message in context: http://www.nabble.com/Zend-Form---_forward%28%29-and-submit-questions-tp24513058p24531456.html Sent from the Zend Framework mailing list archive at Nabble.com.
