cancel
Showing results for 
Search instead for 
Did you mean: 

Contact Form in CMS not working

Contact Form in CMS not working

Hey all, I have tried to make a form submission, but received the error "Unable to submit your request. Please, try again later"

 

After some investigation, it seems that the problem is in this row:

 

Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')

 

Anyone has got any solution for this? Thanks!

11 REPLIES 11

Re: Contact Form in CMS not working

Hi @rareus,

 

Have you added a form into a CMS page?

Can you share how youv'e added the form?

Re: Contact Form in CMS not working

Hi, the form belongs to a template, which is based on the original contact us form from Magento.

Re: Contact Form in CMS not working

Hi @rareus,

 

If that form is into a Magento's CMS page, can you share that page content?

Re: Contact Form in CMS not working

Hi, could you advise where do I get the file? Thanks!

Re: Contact Form in CMS not working

You can get this file from Contacts module under the app/code/core.

Your file path will be,

app/code/core/Mage/Contacts/controllers/IndexController.php
If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Contact Form in CMS not working

Hi, please see attached code:

class Mage_Contacts_IndexController extends Mage_Core_Controller_Front_Action
{

    const XML_PATH_EMAIL_RECIPIENT  = 'contacts/email/recipient_email';
    const XML_PATH_EMAIL_SENDER     = 'contacts/email/sender_email_identity';
    const XML_PATH_EMAIL_TEMPLATE   = 'contacts/email/email_template';
    const XML_PATH_ENABLED          = 'contacts/contacts/enabled';

    public function preDispatch()
    {
        parent::preDispatch();

        if( !Mage::getStoreConfigFlag(self::XML_PATH_ENABLED) ) {
            $this->norouteAction();
        }
    }

    public function indexAction()
    {
        $this->loadLayout();
        $this->getLayout()->getBlock('contactForm')
            ->setFormAction( Mage::getUrl('*/*/post', array('_secure' => $this->getRequest()->isSecure())) );

        $this->_initLayoutMessages('customer/session');
        $this->_initLayoutMessages('catalog/session');
        $this->renderLayout();
    }

    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('*/*/');
        }
    }

}

Re: Contact Form in CMS not working

Your error is coming from catch($Exception $e) block,

check,

catch (Exception $e) {
echo "<pre>";print_r($e->getMessage()); $translate->setTranslateInline(true); Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later')); $this->_redirect('*/*/'); return; }

So Might be issue with your Email configuration is not set in your server, Plz ask for Hosting provider to setup mail configuration.

Or Debug your log in cache block.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Contact Form in CMS not working

Hello @rareus

 

Add below thing into catch function 

 

} catch (Exception $e) {
echo "<pre>";
print_R($e->getMessage());
exit;
}

By above code, you will get actual error.

 

Hope it will help you.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Contact Form in CMS not working


@Sunil Patel wrote:

Hello @rareus

 

Add below thing into catch function 

 

} catch (Exception $e) {
echo "<pre>";
print_R($e->getMessage());
exit;
}

By above code, you will get actual error.

 

Hope it will help you.


Hi, tried the above and I got a blank page.