我正在尝试在产品页面中进行密码验证。它的工作原理,但在提交密码后,它会重定向到新页面并提醒新页面。
我需要在不重定向的同一产品页面中显示提醒
帮帮我......
代码:
应用程序/代码/本地/普尔纳/邮编/控制器/ indexcontroller.php
class Purna_Zipcode_IndexController extends Mage_Core_Controller_Front_Action
{
public function zipcodeAction() {
$data = $this->getRequest()->getParams();
$session = Mage::getSingleton('core/session');
$zipcode = $data['zipcode'];
$collection = Mage::getModel('zipcode/zipcode')
->getCollection()
->addFilter('zipcode', $zipcode, '=')
->getData();
if(count($collection) > 0){
echo "<script>alert(not available);</script>";
} else {
echo "<script>alert(available);</script>";
}
}
}
应用程序/设计/前端/碱/默认/模板/邮编/索引/ zipcode.phtml
<form action="<?php echo Mage::getUrl('zipcode/index/zipcode') ?>" method="post" id="zipcode-submit">
<input type="text" name="zipcode" class="input-text" id="zipcode">
<button type="submit" class="button">Submit</button>
</form>
应用程序/设计/前端/碱/默认/布局/ zipcode.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<zipcode_index_index>
<reference name="root">
<action method="setTemplate">
<template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="zipcode/index" name="zipcode_index" template="zipcode/zipcode.phtml"/>
</reference>
</zipcode_index_index>
</layout>
应用程序/设计/前端/默认/主题/模板/目录/产品/ view.phtml
<?php
echo $this->getLayout()
-> CreateBlock('core/template')
->setTemplate('zipcode/index/zipcode.phtml')
->toHtml()
?>
答案 0 :(得分:0)
从您的代码中,您的xml将在zipcode_index_index操作上加载表单。你能告诉我你是如何使用产品页面上的表格的。
但要实现您的解决方案,您必须使用magento错误消息
$data = $this->getRequest()->getParams();
$session = Mage::getSingleton('core/session');
$zipcode = $data['zipcode'];
$collection = Mage::getModel('zipcode/zipcode')
->getCollection()
->addFilter('zipcode', $zipcode, '=')
->getData();
if(count($collection) > 0){
Mage::getSingleton('core/session')->addError($this->__('not available'));
} else {
Mage::getSingleton('core/session')->addSuccess($this->__('available'));
}
$this->_redirectReferer();
请检查代码,它也将解决您的重定向问题。 $这 - &GT; _redirectReferer(); //这个wiil重定向到引用者