Ejemplo n.º 1
0
 public function addAction()
 {
     $form = new Application_Form_Album();
     $form->submit->setLabel('Add');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         // form validation
         if ($form->isValid($formData)) {
             // collecting the data from user intput
             $dataArray = array('artist' => $form->getValue('artist'), 'title' => $form->getValue('title'), 'price' => $form->getValue('price'));
             //commented after passing
             //$artist = $form->getValue('artist');
             //$title = $form->getValue('title');
             //$albums = new Model_Albums();
             // some db related stuff
             $albums = new Application_Model_DbTable_Albums();
             $albums->addAlbum($dataArray);
             // after success redirect to index action
             $this->_helper->redirector('index');
         } else {
             // if any validation erros,
             // populate the form with previouis data
             $form->populate($formData);
         }
     }
 }
Ejemplo n.º 2
0
 public function addAction()
 {
     $form = new Application_Form_Album();
     $form->submit->setLabel('Add');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $artist = $form->getValue('artist');
             $title = $form->getValue('title');
             $albums = new Application_Model_DbTable_Albums();
             $albums->addAlbum($artist, $title);
             $this->_helper->redirector('index');
         } else {
             $form->populate($formData);
         }
     }
 }