简体   繁体   English

如何在不重定向的情况下在同一页面中显示成功或错误警报

[英]how to display success or error alert in same page without redirecting

I am trying to do pincode validation in product page.我正在尝试在产品页面中进行密码验证。 Its working but after submiting pincode its redirecting to new page and alert also coming in new page.它可以工作,但在提交密码后,它会重定向到新页面并在新页面中发出警报。

I need to display alert in same product page without redirect我需要在不重定向的情况下在同一产品页面中显示警报

Help me..帮我..

Code:代码:

app/code/local/purna/Zipcode/controllers/indexcontroller.php app/code/local/purna/Zipcode/controllers/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>"; 
        }
    }
}

app/design/frontend/base/default/template/zipcode/index/zipcode.phtml app/design/frontend/base/default/template/zipcode/index/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>

app/design/frontend/base/default/layout/zipcode.xml app/design/frontend/base/default/layout/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>

app/design/frontend/default/theme/template/catalog/product/view.phtml应用程序/设计/前端/默认/主题/模板/目录/产品/view.phtml

<?php 
    echo $this->getLayout()
              -> CreateBlock('core/template')
              ->setTemplate('zipcode/index/zipcode.phtml')
              ->toHtml()
?>

from your code your xml will load form on the zipcode_index_index action.从您的代码中,您的 xml 将在 zipcode_index_index 操作上加载表单。 can you tell mw how you are using the form on product page.你能告诉 mw 你是如何使用产品页面上的表格的吗?

but to achieve your solution you must use a magento error messages但要实现您的解决方案,您必须使用 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(); 

please check the code it will also solve your redirection problem.请检查代码它也将解决您的重定向问题。 $this->_redirectReferer(); $this->_redirectReferer(); // this wiil do a redirection to a referrer // 这将重定向到引用者

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么使用AJAX提交的表单重定向到下一页,并且错误/成功消息未显示在同一页面的警报中? - Why the form submitted using AJAX is redirecting to next page and the error/success messages are not displayed into alert on the same page? 如果验证失败,如何使用 ajax 和 php 以模态形式显示错误,如果成功则重定向到其他页面 - How to display error in modal form using ajax and php if validation fail while redirecting to other page if success 重定向到同一页面以及带有Php的成功消息 - Redirecting to same page along with Success Message with Php 在发送带有PHPMailer的电子邮件后,在同一页面上显示成功/失败消息,而无需重新加载或重定向页面 - After sending email with PHPMailer show success/failure message on the same page without reloading or redirecting the page 如何在不刷新页面的情况下在同一{div}上显示表单成功消息? - How can i display form success message on same { div } without refreshing the page? PHP - 显示 404 错误而不重定向到另一个页面 - PHP - Display a 404 Error without redirecting to another page 如何在重定向页面中显示成功消息 - How to show the success message in redirecting page 在将用户重定向到最后一个php页面之前,我如何显示成功弹出消息? - How can i display a success pop up message before redirecting a user to the last php page 将用户重定向回我的主页后,如何显示成功消息? - How do I display a success message after redirecting the user back to my home page? 在使用php和jscript重定向到其他页面后,如何显示ALERT消息? - How to display ALERT massage AFTER redirecting to other page using php and jscript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM