1

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.

1

Its because you are action is contacts/index/post/ so its going to contacts module on IndexController's post method and if you look at this action your message and redirect is set here so you should create another action here and display your custom message and redirect where you want.for example your function could be

 public function customefromAction(){
 //your redirect and messagge//
 } 

and your action

 contacts/index/customefrom/<br>

 //for above to work you have to copy your postAction function content to your action.

alternative you can submit form using post action and set redirect to your action


around line no 113 you can find:

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.'));

just comment it

and change

$this->_redirect('*/*/'); to
$this->_redirect('*/*/customefrom');// this redirect to your action
  • Thanks for the answer Pawan! Real quick, where would I find the area to add my custom public function denoted in the main answer? That seems like the best method here :) – ne0nlight Oct 7 '16 at 13:10
  • copy app\code\core\Mage\Contacts\controllers\IndexController.php to app\code\local\Mage\Contacts\controllers\IndexController.php in this php you can add function – Pawan Oct 7 '16 at 14:04
  • excellent, thank you! I'll get to work on it and comment if I bump into a problem, but thanks for the answer! – ne0nlight Oct 7 '16 at 15:46
  • So I recreated the original post function to public function postSupportAction() and changed the redirect, however the form action <form action="<?php echo Mage::getUrl(); ?>contacts/index/support/" just sends me to 404 of site.com/index.php/contacts/index/support/ which makes sense since that isn't a page, but neither is contacts/index/post/ however that works, any idea where I'm going wrong? Thanks! – ne0nlight Oct 7 '16 at 17:10
  • It should be contacts/index/postsupport because your method is postsupportAction – Pawan Oct 7 '16 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.