After a bunch of head scratching, I have finally gotten a custom contact form with additional information on a seperate cms block from the contact form to take the information and send it off, using a custom template that uses the if statements showed here. Great! We now have a working contact us form, and a custom other form both using the same template but divying up the different information just like I was hoping.
The trick that allowed me to finally end up successfully sending the email (explained here) was to change:
<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post">
to
<form action="<?php echo Mage::getUrl(); ?>contacts/index/post/" id="contactForm" method="post">
Not sure if this was a bad hack or what, but it showed success!
The only hitch I am experiencing now, is when submitting the custom cms blocks contact form, the success notification ends up bringing you to the contact us page with the success message. Any ideas why this happens and how it could just be redirected to the current custom cms blocks page with success notification? Thanks!
--- EDIT WITH FILE INFO ---
- app/code/local/Mage/Contacts/controllers/IndexController.php
Right below the original post function, I have included this;
public function postsupportAction()
{
$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['address']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['city']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['state']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['zip']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['country']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['telephone']) , '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('*/*/postsupport');
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('*/*/');
}
}
- app/design/frontend/smartwave/legenda/template/contacts/support-form.phtml
<form action="<?php echo Mage::getUrl(); ?>contacts/index/postsupport/" id="contactForm" method="post">
(along with all the inner actual form stuff) and the final javascript call of:
<script type="text/javascript">
//<![CDATA[
var contactForm = new VarienForm('contactForm', true);
//]]>
</script>
Using all of this sends me to
http://website.com/index.php/contacts/index/postsupport/
with a 404 error and no email ever being shot off.