3

I am using magento 1.9.I have added a cms page named visit and it displays a form which is given below

app\design\frontend\default\theme\template\sitevisit\form.phtml

<form action="<?php echo Mage::getUrl('contacts/index/new'); ?>" id="contactForm" method="post">
    <div class="fieldset">

        <ul class="form-list">
            <li class="fields">
                <div class="field">
                    <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>
                    <div class="input-box">
                        <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
                    </div>
                </div>
                <div class="field">
                    <label for="name" class="required"><?php echo Mage::helper('contacts')->__('Company') ?></label>
                    <div class="input-box">
                        <input name="company" id="company" title="<?php echo Mage::helper('contacts')->__('Company') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text" type="text" />
                    </div>
                </div>
                <div class="field" style="margin-top: 50px;margin-left: 1px">
                    <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Postcode') ?></label>
                    <div class="input-box">
                        <input name="postcode" id="postcode" title="<?php echo Mage::helper('contacts')->__('Postcode') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
                    </div>
                </div>
                <div class="field" style="margin-top: -43px;margin-left: 425px">
                    <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Preferred Visit Date ') ?></label>
                    <div class="input-box">
                        <input name="v_date" id="v_date" title="<?php echo Mage::helper('contacts')->__('Preferred Visit Date') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
                    </div>
                </div>
                <div class="field" style="margin-top:50px;margin-left: 0px">
                    <label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>
                    <div class="input-box">
                        <input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email" type="text" />
                    </div>
                </div>
             <div class="field" style="margin-top: -43px;margin-left: 425px">
                <label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
                <div class="input-box">
                    <input name="telephone" id="telephone" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text" type="text" />
                </div>
             </div>
            </li>
        </ul>
    </div>
    <div class="buttons-set" style="margin-left: 279px;margin-top: 278px;">
        <p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
        <input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
        <button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
    </div>
</form>

this is copied from contacts form and have changed some fields

On submission of the form the details should be sent via email to mytest1@gmail.com.i want to override the core contacts methods. In the site contats form is also used. I want to use both visit and contactus cms pages

2

It would be better to create new controller (extends Mage_Contacts_IndexController) for posting sitevisit form. This way you will use both old controller for contactus form and new controller for visit form.

  • ok.then how to sent the details to the given email address.plz describe with code – Asha Jun 9 '15 at 10:45
2

If you have already showing this in a page then create a custom controller and change the <?php echo Mage::getUrl('frontname/yourcontroller/customaction'); ?>to your custom controller name and action.If you want to customise core methods then you have overide it. This blog can be helpfull http://www.knightdale-computer-repair.com/coding/overloading-the-magento-contact-controller/

  • ok.then how to sent the details to the given email address.plz describe with code – Asha Jun 9 '15 at 10:57
  • Look in to this class Mage_Contacts_IndexController in postAction method magento has written logic for sending mails you can copy the same code and instead replace this Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT) with your email address – Bharath Jun 9 '15 at 11:04
  • i have changed like this ->sendTransactional( Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), mytest1@gmail.com, null, array('data' => $postObject) ); but not working – Asha Jun 9 '15 at 11:33
  • Are u saying that you are not getting email? or you dont have any content in the email.Check your system.log and exception.log – Bharath Jun 9 '15 at 12:25
1

As per as your code you have set action of form to a new url contacts/index/new add new Action name newAction at Mage_Contacts_IndexController.

So you need to Override Mage_Contacts IndexController and .and put all code of post action to this new.

See How to override a controller in Magento.

config.xml :

<frontend>
        <routers>
            <contacts>
                <args>
                    <modules>
                        <customcontacts before="Mage_Contacts">Amit_Customcontacts</customcontacts>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>

controller:

<?php
require_once Mage::getModuleDir('controllers', "Mage_Contacts").DS."IndexController.php";
class Amit_Customcontacts_IndexController extends Mage_Contacts_IndexController
{
    public function newAction()
    {
        $Cmsurl=Mage::getUrl('').'YOUR_CMS_PAGE_IDENTOFIER';

        //Mage::app()->getFrontController()->getResponse()->setRedirect($url); 

        $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('*/*/');
               Mage::app()->getFrontController()->getResponse()->setRedirect($Cmsurl);

                return;
            } catch (Exception $e) {
                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
               Mage::app()->getFrontController()->getResponse()->setRedirect($Cmsurl);
                return;
            }

        } else {
               Mage::app()->getFrontController()->getResponse()->setRedirect($Cmsurl);
        }
    }

} 

Note: $Cmsurl=Mage::getUrl('').'YOUR_CMS_PAGE_IDENTOFIER'; your cms page url

  • yes.i have created custom controller with new Action .i want to sent the details from the form to a custome mail address.what is the code for that – Asha Jun 9 '15 at 11:04
  • not working.in the code custome email is not setting any where – Asha Jun 9 '15 at 11:18
  • sorry action name is wrong. its should newAction. Please ckd code of controllers – Amit Bera Jun 9 '15 at 11:20
  • ok .i have changed the action name.but i want to sent the details to mytest1@gmail.com.where i set this mailid? – Asha Jun 9 '15 at 11:24
  • you need set mytest1@gmail.com to admin>system>configuration>contacts>Send Emails To> set here email address – Amit Bera Jun 9 '15 at 11:33

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.