html嵌入了php中的条件if语句

时间:2022-11-22 21:24:02

I feel like this should be pretty simple, but I'm not getting the results that I want. I have an email signup form that displays across all my websites. If they happen to visit my website with the store code ama_br the email signup disappears. That is fine and that works. My elseif statement is a different form than the one that is displayed across all store views and I want this new form to only appear when it's store code ama_ca. It does not work for me and I don't see anything wrong with my code. Please help. Thank you.

我觉得这应该很简单,但是我没有得到我想要的结果。我有一个电子邮件注册表,在我所有的网站上都有。如果他们碰巧用商店代码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;?>

1 个解决方案

#1


1  

Description You have done every thing right but you just miss the trick look carefully on your if statement Logic that is if your Code not equals to ama_br that is it can be equal to ama_ca so it will show the form in if statement for ama_ca as well as on any other string from ama_br so the form you are trying to show on Code equals to ama_ca is not showing. Try one of the following it will resolve your query.

描述你所做的每件事正确的,但是你只是想念诀窍仔细观察if语句的逻辑是,如果您的代码不等于ama_br可以等于ama_ca所以它将显示在if语句形式ama_ca以及其他任何字符串从ama_br所以你想节目形式代码等于ama_ca不显示。尝试以下方法之一,它将解析您的查询。

Code

代码

        <?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; ?>

OR

       <?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; ?>

#1


1  

Description You have done every thing right but you just miss the trick look carefully on your if statement Logic that is if your Code not equals to ama_br that is it can be equal to ama_ca so it will show the form in if statement for ama_ca as well as on any other string from ama_br so the form you are trying to show on Code equals to ama_ca is not showing. Try one of the following it will resolve your query.

描述你所做的每件事正确的,但是你只是想念诀窍仔细观察if语句的逻辑是,如果您的代码不等于ama_br可以等于ama_ca所以它将显示在if语句形式ama_ca以及其他任何字符串从ama_br所以你想节目形式代码等于ama_ca不显示。尝试以下方法之一,它将解析您的查询。

Code

代码

        <?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; ?>

OR

       <?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; ?>