我试图用PHP if条件显示文本内容,但我有几个错误,我没有看到错误在哪里有人可以帮助我,这里是代码:
<?php
if(
isset($_POST['send']) &&
!validateDiscp($_POST['Discp']) || !validateSize($_POST['Size'])
) : ?>
<div id="error">
<ul>
<?php if(!validateDiscp($_POST['Discp'])):?>
<li><strong>Discription:</strong>Discription need to be larger then 10!</li>
<?php endif?>
<?php if(!validateSize($_POST['Size'])):?>
<li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
<?php endif ?>
</ul>
</div>
<?php elseif(isset($_POST['send'])):?>
<div id="error" class="valid">
<ul>
<li><strong>Congratulations!</strong> All fields are OK ;)</li>
</ul>
</div>
<?php endif ;?>
答案 0 :(得分:1)
我会重写整个外部块。而是做:
<? if( isset($_POST['send'])&& !validateDiscp($_POST['Discp']) || !validateSize($_POST['Size']) ) { ?>
<div id="error">
<ul>
<?php if(!validateDiscp($_POST['Discp'])) { ?>
<li><strong>Discription:</strong> Discription need to be larger then 10!</li>
<?php } ?>
<?php if(!validateSize($_POST['Size'])) { ?>
<li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
<?php } else {
$nothing = true;
?>
</ul>
</div>
<?php if( isset( $nothing ) and isset($_POST['send'] ) ) { ?>
<div id="error" class="valid">
<ul>
<li><strong>Congratulations!</strong> All fields are OK ;)</li>
</ul>
</div>
<? } ?>
我认为你的逻辑中存在缺陷,你有一个悬而未决的其他声明。而是添加一些逻辑来检测其他情况何时被击中并添加您的额外逻辑和您的好处。
答案 1 :(得分:1)
所有endif
需要;
后面的if
。此外,我不确定这是实际错误还是只是代码被包装,但请确保您的第一个{{1}}全部在一行。
答案 2 :(得分:0)
<?php if(isset($_POST['send']) && !validateDiscp($_POST['Discp'])|| !validateSize($_POST['Size']) ):?>
<div id="error">
<ul>
<?php if(!validateDiscp($_POST['Discp'])):?>
<li><strong>Discription:</strong> Discription need to be larger then 10!</li>
<?php endif;?>
<?php if(!validateSize($_POST['Size'])):?>
<li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
<?php endif; ?>
</ul>
</div>
<?php elseif(isset($_POST['send']) ):?>