protected function _saveVacancy() { // First of all we need to validate and sanitise the input from the form $requiredText = new Zend_Validate(); $requiredText->addValidator(new Zend_Validate_NotEmpty()); $filters = array('id' => 'Digits', 'jobTitle' => 'StringTrim', 'reportingTo' => 'StringTrim', 'location' => 'StringTrim', 'startDate' => 'StringTrim', 'endDate' => 'StringTrim', 'jobDescription' => 'StringTrim'); $validators = array('id' => array('allowEmpty' => true), 'jobTitle' => $requiredText, 'reportingTo' => array('allowEmpty' => true), 'location' => array('allowEmpty' => true), 'startDate' => $requiredText, 'endDate' => $requiredText, 'jobDescription' => array('allowEmpty' => true)); $input = new Zend_Filter_Input($filters, $validators, $_POST); if ($input->isValid()) { // Data is all valid, formatted and sanitized so we can save it in the database $careers = new Datasource_Cms_Careers(); if (!$input->id) { // This is a new vacancy so we need to create a new ID $vacancyID = $careers->addNew($input->jobTitle, $input->reportingto, $input->location, $input->getUnescaped('startDate'), $input->getUnescaped('endDate'), $input->getUnescaped('jobDescription')); } else { $careers->saveChanges($input->id, $input->jobTitle, $input->reportingTo, $input->location, $input->getUnescaped('startDate'), $input->getUnescaped('endDate'), $input->getUnescaped('jobDescription')); $vacancyID = $input->id; } // Changes saved - so send them back with a nice success message $this->_helper->getHelper('FlashMessenger')->addMessage(array('saved' => true)); $this->_helper->getHelper('Redirector')->goToUrl('/cms-admin/vacancies'); } else { // Invalid data in form /* print_r($_POST); print_r($input->getErrors()); print_r($input->getInvalid()); */ } }