2012-08-08 98 views
0

登錄我需要顯示和隱藏一種形式是客戶或者沒有登錄顯示/隱藏數據,如果用戶登錄/未在Magento

我有這樣的幫手。

<?php 
    if ($this->helper('customer')->isLoggedIn()) { 
     echo "Hide Form"; 
    } else { 
     echo "<form id="form1" name="form1" method="post" action="post.php"> 
<input name="Type your name" type="text" value="name" /> 
<label> 
    <input type="submit" name="send" id="send" value="Submit" /> 
</label> 
</form>"; 
    } 
    ?> 

感謝

回答

11
<?php 
    if ($this->helper('customer')->isLoggedIn()) { 
     $showHide = "style=display:none"; 
    } else { 
     $showHide = "style=display:block"; 
    }?> 
    <form id="form1" name="form1" method="post" action="post.php" <?php echo $showHide;?> > 
     <input name="Type your name" type="text" value="name" /> 
     <label> 
      <input type="submit" name="send" id="send" value="Submit" /> 
     </label> 
    </form> 
+0

感謝配發,這真的 – NeoCaste 2012-09-26 13:09:23

+0

很高興!請標記答案爲已接受,如果它幫助你。 – Kalpesh 2012-10-11 11:40:57

+0

感謝哥們:) – w3debugger 2015-04-07 11:31:34

1

我的猜測是你的問題來自你正在迴應的HTML中的引號。 Php認爲該塊爲echo "<form id=",後面跟着一堆亂碼,它不知道該如何處理。

解決方案取決於代碼塊的位置。如果它在一個模板(.phtml)文件中,那麼Kalpesh Mehta的方法就可以工作。

如果它是像塊,助手或控制器的東西,他們的解決方案將無法正常工作。在這種情況下,最簡單的解決辦法是改變兩個外面的雙引號(「),以單引號(')。

0

我已經嘗試在審查文件,這個選項一個.phtml

<script type="text/javascript"> 
function hideshow(which){ 
if (!document.getElementById) 
return 
if (which.style.display=="block") 
which.style.display="none" 
else 
which.style.display="block" 
} 
</script> 
<?php 
    if ($this->helper('customer')->isLoggedIn()) { 
     $showHide = "style=display:none"; 
    } else { 
     $showHide = "style=display:block"; 
    }?> 
<?php if(Mage::helper('oscheckout')->isCouponActive()):?> 
<div class="fivecol" id="coupon-container"> 
    <?php echo $this->getChildHtml('coupon') ?> 
</div>