簡體   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