繁体   English   中英

html嵌入条件if语句在php中

[英]html embedded conditional if statements in php

我觉得这应该很简单,但我没有得到我想要的结果。 我有一个显示在我所有网站上的电子邮件注册表单。 如果他们碰巧使用商店代码ama_br访问我的网站,电子邮件注册就会消失。 那很好,而且有效。 我的elseif语句与在所有商店视图中显示的形式不同,我希望这个新表格只在它的商店代码ama_ca时出现。 它对我不起作用,我没有发现我的代码有任何问题。 请帮忙。 谢谢你。

            <?php if (Mage::app()->getStore()->getCode() != "ama_br"):?>
                <ul>
                    <li><?php echo $this->__('Email Sign Up')?></li>
                    <li>
                        <form action="<?php echo $this->getUrl('email_preferences')?>" method="get" id="newsletter-validate-detail">
                            <input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('Enter Email address')?>" title="<?php echo $this->__('Enter Email address')?>' class="required-entry validate-email">
                            <button class="submit">+</button>
                            <input type="hidden" name="source" value="nt">
                        </form>
                    </li>
                    <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo')?></li>
                </ul>

            <?php elseif (Mage::app()->getStore()->getCode() == "ama_ca"):?>
                <ul>
                    <li><?php echo $this->__('Email Sign Up')?></li>
                    <li>
                <form method="post" action="http://enews.******.com/q/9MNK4U4iV9Mutb9YzTxF2zRWDIPgKoX0F0" accept-charset="UTF-8">
                        <input type="hidden" name="crvs" value="6hZNXcISD79ac2Empmsr2az_B3Qc5osTNmkOdNHleqhPIYmsxEOe6PbgaUo-3WBn_Vbgorrbk4qjekx7w4tljA">
                        <input type="hidden" name="CheckBox.Source.ca_footer" value="on">
                        <input name="email" type="text" id="newsletter" placeholder="Enter Email address" title="Enter Email address' class=" required-entry="">
                        <input type="hidden" id="submit" value="Sign Up">
                        </form>
                    </li>
                    <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo')?></li>
                </ul>
            <?php endif;?>

描述你做对了每一件事,但你只是错过了仔细看你的 if 语句的技巧 如果你的代码不等于ama_br也就是它可以等于ama_ca所以它也会在ama_ca 的if 语句中显示形式与来自ama_br 的任何其他字符串一样,因此您尝试在 Code 上显示的表单等于ama_ca未显示。 尝试以下方法之一,它将解决您的查询。

代码

        <?php if (Mage::app()->getStore()->getCode() == "ama_ca"): ?>
          <ul>
            <li><?php echo $this->__('Email Sign Up') ?></li>
            <li>
            <form method="post" action="http://enews.******.com/q/9MNK4U4iV9Mutb9YzTxF2zRWDIPgKoX0F0" accept-charset="UTF-8">
            <input type="hidden" name="crvs" value="6hZNXcISD79ac2Empmsr2az_B3Qc5osTNmkOdNHleqhPIYmsxEOe6PbgaUo-3WBn_Vbgorrbk4qjekx7w4tljA">
            <input type="hidden" name="CheckBox.Source.ca_footer" value="on">
            <input name="email" type="text" id="newsletter" placeholder="Enter Email address" title="Enter Email address' class=" required-entry="">
            <input type="hidden" id="submit" value="Sign Up">
            </form>
            </li>
           <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
         </ul>

        <?php elseif (Mage::app()->getStore()->getCode() != "ama_br"): ?>
          <ul>
            <li><?php echo $this->__('Email Sign Up') ?></li>
            <li>
              <form action="<?php echo $this->getUrl('email_preferences') ?>" method="get" id="newsletter-validate-detail">
              <input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('Enter Email address') ?>" title="<?php echo $this->__('Enter Email address') ?>' class="required-entry validate-email">
                   <button class="submit">+</button>
              <input type="hidden" name="source" value="nt">
              </form>
              </li>
              <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
             </ul>
        <?php endif; ?>

或者

       <?php if (Mage::app()->getStore()->getCode() != "ama_br" && Mage::app()- >getStore()->getCode() != "ama_ca"): ?>
          <ul>
           <li><?php echo $this->__('Email Sign Up') ?></li>
            <li>
            <form action="<?php echo $this->getUrl('email_preferences') ?>" method="get" id="newsletter-validate-detail">
            <input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('Enter Email address') ?>" title="<?php echo $this->__('Enter Email address') ?>' class="required-entry validate-email">
                   <button class="submit">+</button>
                   <input type="hidden" name="source" value="nt">
            </form>
       </li>
       <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
      </ul>

      <?php elseif (Mage::app()->getStore()->getCode() == "ama_ca"): ?>
      <ul>
          <li><?php echo $this->__('Email Sign Up') ?></li>
      <li>
        <form method="post" action="http://enews.******.com/q/9MNK4U4iV9Mutb9YzTxF2zRWDIPgKoX0F0" accept-charset="UTF-8">
            <input type="hidden" name="crvs" value="6hZNXcISD79ac2Empmsr2az_B3Qc5osTNmkOdNHleqhPIYmsxEOe6PbgaUo-3WBn_Vbgorrbk4qjekx7w4tljA">
            <input type="hidden" name="CheckBox.Source.ca_footer" value="on">
            <input name="email" type="text" id="newsletter" placeholder="Enter Email address" title="Enter Email address' class=" required-entry="">
            <input type="hidden" id="submit" value="Sign Up">
        </form>
    </li>
       <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo')  ?></li>
    </ul>
    <?php endif; ?>

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM