thismethod thismethod - 1 year ago 70
HTML Question

html embedded conditional if statements in php

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.

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

Answer Source

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.

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