|
| 1 | +<?php |
| 2 | + |
| 3 | +require_once(Mage::getModuleDir('controllers','Mage_Contacts').DS.'IndexController.php'); |
| 4 | + |
| 5 | +class RG_Contacts_IndexController extends Mage_Contacts_IndexController |
| 6 | +{ |
| 7 | + public function indexAction() |
| 8 | + { |
| 9 | + $this->loadLayout(); |
| 10 | + $this->getLayout()->getBlock('contactForm') |
| 11 | + ->setFormAction( Mage::getUrl('*/*/post', array('_secure' => $this->getRequest()->isSecure())) ); |
| 12 | + |
| 13 | + $this->_initLayoutMessages('customer/session'); |
| 14 | + $this->_initLayoutMessages('catalog/session'); |
| 15 | + $this->renderLayout(); |
| 16 | + } |
| 17 | + |
| 18 | + public function postAction() |
| 19 | + { |
| 20 | + $post = $this->getRequest()->getPost(); |
| 21 | + if ( $post ) { |
| 22 | + $translate = Mage::getSingleton('core/translate'); |
| 23 | + /* @var $translate Mage_Core_Model_Translate */ |
| 24 | + $translate->setTranslateInline(false); |
| 25 | + try { |
| 26 | + $postObject = new Varien_Object(); |
| 27 | + $postObject->setData($post); |
| 28 | + |
| 29 | + $error = false; |
| 30 | + |
| 31 | + if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) { |
| 32 | + $error = true; |
| 33 | + } |
| 34 | + |
| 35 | + if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) { |
| 36 | + $error = true; |
| 37 | + } |
| 38 | + |
| 39 | + if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) { |
| 40 | + $error = true; |
| 41 | + } |
| 42 | + |
| 43 | + if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) { |
| 44 | + $error = true; |
| 45 | + } |
| 46 | + |
| 47 | + if ($error) { |
| 48 | + throw new Exception(); |
| 49 | + } |
| 50 | + $mailTemplate = Mage::getModel('core/email_template'); |
| 51 | + /* @var $mailTemplate Mage_Core_Model_Email_Template */ |
| 52 | + $mailTemplate->setDesignConfig(array('area' => 'frontend')) |
| 53 | + ->setReplyTo($post['email']) |
| 54 | + ->sendTransactional( |
| 55 | + Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), |
| 56 | + Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), |
| 57 | + Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT), |
| 58 | + null, |
| 59 | + array('data' => $postObject) |
| 60 | + ); |
| 61 | + |
| 62 | + if (!$mailTemplate->getSentSuccess()) { |
| 63 | + throw new Exception(); |
| 64 | + } |
| 65 | + |
| 66 | + $translate->setTranslateInline(true); |
| 67 | + |
| 68 | + Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.')); |
| 69 | + $this->_redirectReferer(); |
| 70 | + |
| 71 | + return; |
| 72 | + } catch (Exception $e) { |
| 73 | + $translate->setTranslateInline(true); |
| 74 | + |
| 75 | + Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later')); |
| 76 | + $this->_redirectReferer(); |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + } else { |
| 81 | + $this->_redirectReferer(); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments