This is the predefined post function inside Magento controller.
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; //orignal code
$error = false;
}
if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
$error = true;
}
Mage::log($post['producturl']);
if (!Zend_Validate::is(trim($post['producturl']) , 'NotEmpty')) {
$error = true;
}
//if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
// $error = true;
//}
Mage::log($error);
Mage::log($postObject);
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('*/*/');
}
}
When I log the producturl attribute, it prints the correct view.But I do not get that value in my email. How to get that value binded so it gets send to the email?
My form looks like this:
<form action="<?php echo $this->getUrl('contacts/index/post'); ?>" id="contactForm" method="post">
<div class="row">
<div class="col-sm-12">
<!--<label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>-->
<div class="input-box">
<input name="name" id="name" placeholder="Name*" title="<em>*</em><?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="col-sm-12">
<!--<label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>-->
<div class="input-box">
<input name="email" id="email" placeholder="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="col-sm-12">
<!--<label for="telephone" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Mobile') ?></label>-->
<div class="input-box">
<input name="telephone" id="telephone" placeholder="Mobile*" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text required-entry" type="text" />
</div>
</div>
<div class="col-sm-12">
<div class="input-box">
<input name="producturl" id="producturl" placeholder="Product URL*" title="<?php echo Mage::helper('contacts')->__('ProductURL') ?>" value="url hai bhai" class="input-text required-entry" type="text" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<!--<label for="comment" class=""><?php echo Mage::helper('contacts')->__('Comment') ?></label>-->
<div class="input-box input-textarea">
<textarea name="comment" id="comment" rows="3" placeholder="Message" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class=" input-text" placeholder="<?php echo Mage::helper('contacts')->__('Comment') ?>" style="width: 100%; height: 15%;resize:none;"></textarea>
</div>
</div>
</div>
<div class="row" style="text-align: center">
<div class="col-sm-12" style="padding-top:2%">
<input type="text" name="hideit" id="hideit" value="url hai bhai" style="display:none !important;" />
<button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('BOOK A DESIGNER') ?></span></span></button>
</div>
</div>
</div>
</div>