Magento控制器中的值未绑定 [英] Value not getting bind in the Magento controller
问题描述
这是Magento控制器中预定义的发布功能.
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('*/*/');
}
}
当我记录producturl属性时,它会打印正确的视图.但是我没有在电子邮件中获得该值.如何绑定该值,以便将其发送到电子邮件?
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?
我的表单如下:
<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>
推荐答案
因此,电子邮件模板是html文件,您可以在文件夹app/locale/[some_locale]/template/
中找到,如果您的语言环境是美国英语,则some_locale
将是en_US
,如果是比利时的法语,则为fr_BE
,因此这是 ISO 3166-1 alpha-2 .
So, the emails templates are html files that you can actually find in the folder app/locale/[some_locale]/template/
if your locale is english of the US then some_locale
will be en_US
, if that is french from Belgium, then it will be fr_BE
, so that is the language code on 2 letter as defined by ISO 639-1 then an underscore _
and country code as defined by ISO 3166-1 alpha-2.
如果对注释中实际声明的模板的句柄进行全局搜索,则文件名将是您可以找到的.
And the name of the file will be something you could find if you do a global search on the handle of the template you actually stated in you comment.
因此,这里contacts_email_email_template
实际上在app/code/core/Mage/Contacts/etc/config.xml
中定义为文件contact_form.html
:
So here contacts_email_email_template
is actually defined in app/code/core/Mage/Contacts/etc/config.xml
as being the file contact_form.html
:
<template>
<email>
<contacts_email_email_template translate="label" module="contacts">
<label>Contact Form</label>
<file>contact_form.html</file>
<type>text</type>
</contacts_email_email_template>
</email>
</template>
因此,如果您去编辑下面在此处复制的app/locale/en_US/template/email/contact_form.html
,并在其中添加了产品url值,则应该可以:
So if you go and edit app/locale/en_US/template/email/contact_form.html
that I reproduced here below and in which I added your product url value, that should work :
<!--@subject Contact Form@-->
<!--@vars
{"var data.name":"Sender Name",
"var data.email":"Sender Email",
"var data.telephone":"Sender Telephone",
"var data.comment":"Comment"}
@-->
Name: {{var data.name}}
Email: {{var data.email}}
Telephone: {{var data.telephone}}
Comment: {{var data.comment}}
<!-- this below line is actually what you are after -->
Product URL : {{var data.producturl}}
data
,实际上是作为函数sendTransactional
data
, actually being the key of the array you are passing as the fifth argument of the function sendTransactional
这篇关于Magento控制器中的值未绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!