我需要显示并隐藏一个表单是客户是否登录。
我有这个帮手:
<?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>";
}
?>
由于
答案 0 :(得分: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>
答案 1 :(得分:1)
我的猜测是你的问题来自你正在回应的html中的引号。 Php认为那个块是echo "<form id="
,然后是一堆乱码,它不知道该怎么做。
解决方案取决于代码块的位置。如果它在模板(.phtml)文件中,那么Kalpesh Mehta的方法将起作用。
如果它像块,助手或控制器那样,他们的解决方案就无法工作。在这种情况下,最简单的解决方案是将两个外部双引号(“)更改为单引号(')。
答案 2 :(得分: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>