请隐藏此表单(form.php)if this condition is TRUE
。也就是说,我不希望整个表单显示if this condition is TRUE
。谢谢。
Condition: if ($session_id == $query1){
form.php的
<form action="tmembers.php" method="post">
<input type="hidden' value='<?php echo $_GET['id']; ?>' name="id"/></br>
<select multiple="true" name="members[]" val id="member" class="">
<?php while($record = $stmt->fetch()) : ?>
<option value="<?php echo $record['id'] ; ?>"> <?php echo $record['surname']; ?> <?php echo $record['firstname'] ; ?> </option>
<?php endwhile; ?>
</select></br>
<input type="submit" value="Send Invite" name="invite" class=""/>
</form>
答案 0 :(得分:0)
<?php
if ($session_id != $query1){
?>
<form action="tmembers.php" method="post">
<input type="hidden' value='<?php echo $_GET['id']; ?>' name="id"/></br>
<select multiple="true" name="members[]" val id="member" class="">
<?php while($record = $stmt->fetch()) : ?>
<option value="<?php echo $record['id'] ; ?>"> <?php echo $record['surname']; ?> <?php echo $record['firstname'] ; ?> </option>
<?php endwhile; ?>
</select></br>
<input type="submit" value="Send Invite" name="invite" class=""/> </div>";
</form>
<?php
}else{
}
?>
在表单中添加一个类会更容易。
<form action="tmembers.php" method="post" <?php if ($session_id == $query1){ echo 'class="hide"'; ?> >
然后使用以下css:
.hide{
display: none;
}
答案 1 :(得分:0)
如果您不希望在此条件为true
时显示表单,则需要更改运算符
所以下面这个:
if ($session_id == $query1) //EQUAL
成为
if ($session_id != $query1) //NOT EQUAL
答案 2 :(得分:0)
如果将php条件置于表单之上,那么如果它不是true
php就不会渲染表单。
PHP
<?php if ($session_id != $query1){ ?>
<form action="tmembers.php" method="post">
<input type="hidden' value='<?php echo $_GET['id']; ?>' name="id"/></br>
<select multiple="true" name="members[]" val id="member" class="">
<?php while($record = $stmt->fetch()) : ?>
<option value="<?php echo $record['id'] ; ?>"> <?php echo $record['surname']; ?> <?php echo $record['firstname'] ; ?> </option>
<?php endwhile; ?>
</select></br>
<input type="submit" value="Send Invite" name="invite" class=""/> </div>";
</form>
<?php } ?>
如果条件不是页面加载,你可以做一些Js:
/*Some JS event if needed before*/
if(<?php $session_id != $query1 ?>){
$('form').hide();
}