public function updateAction() { // generate input form $form = new Webteam_Form_VideoUpdate(); $this->view->form = $form; if ($this->getRequest()->isPost()) { // if POST request // test if input is valid // retrieve current record // update values and replace in database $postData = $this->getRequest()->getPost(); if ($form->isValid($postData)) { $input = $form->getValues(); $item = Doctrine::getTable('Webteam_Model_Video')->find($input['VideoID']); $item->fromArray($input); $item->save(); $this->_helper->getHelper('FlashMessenger')->addMessage('The record was successfully updated.'); $this->_redirect('/admin/catalog/video/success'); } } else { // if GET request // set filters and validators for GET input // test if input is valid // retrieve requested record // pre-populate form $filters = array('id' => array('HtmlEntities', 'StripTags', 'StringTrim')); $validators = array('id' => array('NotEmpty', 'Int')); $input = new Zend_Filter_Input($filters, $validators); $input->setData($this->getRequest()->getParams()); if ($input->isValid()) { $q = Doctrine_Query::create()->from('Webteam_Model_Video i')->where('i.VideoID = ?', $input->id); $result = $q->fetchArray(); if (count($result) == 1) { // perform adjustment for date selection lists $this->view->form->populate($result[0]); } else { throw new Zend_Controller_Action_Exception('Page not found', 404); } } else { throw new Zend_Controller_Action_Exception('Invalid input'); } } }
public function init() { // get parent form parent::init(); $VideoID = $this->getElement('VideoID'); //$VideoID->setAttrib('disabled', true); $VideoID->setAttrib('readonly', true); $this->removeElement('UserID'); $this->removeElement('VideoType'); $this->removeElement('UserName'); $this->removeElement('ImageURL'); $this->removeElement('VideoPath'); $this->removeElement('VideoFileName'); // set form action (set to false for current URL) $this->setAction('/user/catalog/video/update'); }