I have successfully created an extension that adds all Magento's default contact inquiry submissions into a database. It works great.
I have added an option under the 'Customers' menu that uses Magento's grid to add the contact form submissions into grid.
I am able to mass select the captured data for the purpose of deleting.
I have also added a "Resend" option to the actions and am able to execute:
public function massResendAction() {
$post = $this->getRequest()->getPost();
Zend_Debug::dump($post);
die('here');
}
I have added a new action called "Mass Resend":
array(3) {
["form_key"] => string(16) "Be8rJzWBona0R2Ij"
["enhancedform_id"] => array(2) {
[0] => string(2) "12"
[1] => string(2) "13"
}
["massaction_prepare_key"] => string(15) "enhancedform_id"
}
here
What I would like to do is use Magento's built in Contacts form post action:
app/code/core/Mage/Contacts/controllers/IndexController.php
public function postAction()
{
$post = $this->getRequest()->getPost();
if ( $post ) {
$translate = Mage::getSingleton('core/translate');
/* @var $translate Mage_Core_Model_Translate */
$translate->setTranslateInline(false);
try {
$postObject = new Varien_Object();
$postObject->setData($post);
$error = false;
if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
$error = true;
}
if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
$error = true;
}
if ($error) {
throw new Exception();
}
$mailTemplate = Mage::getModel('core/email_template');
/* @var $mailTemplate Mage_Core_Model_Email_Template */
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject)
);
if (!$mailTemplate->getSentSuccess()) {
throw new Exception();
}
$translate->setTranslateInline(true);
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.'));
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
$translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
$this->_redirect('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
Instead of duplicating this code.
Best Answer
Inchoo did a really nice post about rewriting just about anything (read more here) so we can user that.
In your
config.xml
Now for your controller
controllers/IndexController.php