如果有變化的行動,那麼你需要創建一個擴展which routing url is customcontacts
並創建Indexcontroller.php並創造contolers行動postAction
更多細節如何創建一個模塊http://www.amitbera.com/create-an-magento-extension-with-custom-database-table/。
爲你工作,修改config.xml的是
<?xml version="1.0" ?>
<config>
<modules>
<Amit_Custommodule>
<version>1.0.0</version>
</Amit_Custommodule>
</modules>
<global>
<!-- start of block -->
<blocks>
<custommodule>
<class>Amit_Custommodule_Block</class>
</custommodule>
</blocks>
</global>
<!-- start of routers
-->
<frontend>
<routers>
<custommodule>
<use>standard</use>
<args>
<module>Amit_Custommodule</module>
<frontName>customcontacts</frontName>
</args>
</custommodule>
</routers>
</frontend>
</config>
indexController的代碼應該是
<?php
class Amit_Custommodule_IndexController extends Mage_Core_Controller_Front_Action{
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 ($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('*/*/');
}
}
}
$此 - > _重定向( '/ /');根據你頁面的url
變化,如果窗體頁是聯繫人/索引/然後改變這種
$此 - > _重定向( '觸點/指數/') ; 爲了得到成功/失敗消息<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
表單頁面添加以下代碼
必須檢查
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('catalog/session');
在形式上動作控制器存在 更
http://freegento.com/doc/d9/d7c/_contacts_2controllers_2_index_controller_8php-source.html
TY:D一定要考它 –