public function applyAction() { $this->view->pageTitle = 'Careers'; if ($this->getRequest()->isPost()) { // Handle the cv file and form data $filters = array('name' => 'StringTrim', 'tel' => 'StringTrim', 'email' => 'StringTrim', 'enquiry' => 'StringTrim'); $validators = array('name' => array('NotEmpty', 'messages' => 'Please enter your name'), 'tel' => array('NotEmpty', 'messages' => 'Please enter your telephone number'), 'email' => array('NotEmpty', 'messages' => 'Please enter your email address'), 'enquiry' => array('NotEmpty', 'messages' => 'Please tell us why this position interests you')); $input = new Zend_Filter_Input($filters, $validators, $_POST); if ($input->isValid()) { $upload = new Zend_File_Transfer(); // Make sure the file is actually a document $upload->clearValidators(); $upload->setOptions(array('ignoreNoFile' => true)); //$upload->addValidator('MimeType', false, array('application/msword', 'application/pdf', 'application/rtf', 'text/plain')); if ($upload->isValid()) { $params = Zend_Registry::get('params'); $uploadPath = $params->cms->fileUploadPath; $upload->setDestination($uploadPath); $upload->receive(); $fileInfo = $upload->getFileInfo(); $emailer = new Application_Core_Mail(); $emailer->setTo($params->email->careers, 'HomeLet'); $emailer->setFrom($input->email, $input->name); $emailer->setSubject('HomeLet - Job Application (' . $input->position . ')'); $bodyHtml = 'Position : ' . $input->position . '<br />'; $bodyHtml .= 'Name : ' . $input->name . '<br />'; $bodyHtml .= 'Email : ' . $input->email . '<br />'; $bodyHtml .= 'Tel : ' . $input->tel . '<br />'; $bodyHtml .= 'Enquiry : <pre>' . $input->enquiry . '</pre><br />'; if ($fileInfo['cv_file']['type'] !== null) { $emailer->addAttachment($fileInfo['cv_file']['destination'] . '/' . $fileInfo['cv_file']['name'], $fileInfo['cv_file']['name']); } $emailer->setBodyHtml($bodyHtml); if ($emailer->send()) { $this->_helper->redirector('thanks', 'careers'); } else { } } else { // Invalid file type $this->view->errors = array('cv_file' => 'Invalid file type'); $this->view->name = $input->name; $this->view->tel = $input->tel; $this->view->email = $input->email; $this->view->enquiry = $input->enquiry; } } else { // Invalid form data $this->view->errors = $input->getMessages(); $this->view->name = $input->name; $this->view->tel = $input->tel; $this->view->email = $input->email; $this->view->enquiry = $input->enquiry; } } $careerUrl = $this->getRequest()->getParam('careerID'); $careerID = substr($careerUrl, 0, strpos($careerUrl, '-')); $careers = new Datasource_Cms_Careers(); $career = $careers->getById($careerID); $this->view->title = $career['title']; $this->view->id = $career['id']; }
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()); */ } }