简体   繁体   English

如果php帖子为空,则隐藏字段

[英]Hiding field if php post is empty

I have a form on page1.php, and when I click submit, it leads to page2.php which summarizes the selections. 我在page1.php上有一个表单,当我单击提交时,它会导致page2.php汇总选择。 Below is the code on page2.php to get the selected information. 下面是page2.php上的代码,用于获取所选信息。

I am trying to hide certain rows if the php post is empty. 如果php帖子为空,我试图隐藏某些行。

For example, if you see the code below, there is a Date, Time, From, To and Additional Stop. 例如,如果您看到下面的代码,则会有Date,Time,From,To和Additional Stop。 The first 4 lines are mandatory so it will appear always, however the last line, Additional stop is not mandatory, so when I don't fill up that field in the previous page1.php, it will appear on page2.php as "Additional Stop: (empty space). 前4行是强制性的,所以它总是会出现,但是最后一行,附加停止不是强制性的,所以当我没有在前一个page1.php中填写该字段时,它将在page2.php上显示为“附加”停止:(空白区域)。

Is there a way to have the word Additional Stop: only appear IF the php post add1 has been filled up, and if it has been left blank, it is hidden? 有没有办法让单词附加停止:只有在PHP帖子add1已被填满时出现,如果它已被留空,它是隐藏的吗?

<dt>Date</dt>
<dd><?php echo isset($_POST['date']) ? $_POST['date'] : ''; ?></dd>
<dt>Time</dt>
<dd><?php echo isset($_POST['time']) ? $_POST['time'] : ''; ?></dd>
<dt>From</dt>
<dd><?php echo isset($_POST['pick']) ? $_POST['pick'] : ''; ?></dd>
<dt>To</dt>
<dd><?php echo isset($_POST['drop']) ? $_POST['drop'] : ''; ?></dd>
<dt>Additional Stop</dt>
<dd><?php echo isset($_POST['add1']) ? $_POST['add1'] : ''; ?></dd>

*I am new here, If I made a mistake with the tags let me know and I will change it. *我是新来的,如果我用标签弄错了让我知道,我会改变它。 I tagged php because there is an above php code, html because its html and javascript because i think it may require javascript to be sorted. 我标记了PHP,因为有一个上面的PHP代码,HTML,因为它的HTML和JavaScript,因为我认为它可能需要javascript进行排序。 I say this because I was flamed previously for wrong tags. 我之所以这么说,是因为我之前因错误的标签而受到了抨

check if $_POST['add1'] is set or not 检查是否设置了$_POST['add1']

try this 尝试这个

<?php if(isset($_POST['add1'])){ ?>
<dt>Additional Stop</dt>
<dd><?php echo isset($_POST['add1']) ? $_POST['add1'] : ''; ?></dd>
<?php } ?>

Here you go: 干得好:

<?php if(isset($_POST['add1']) && !empty($_POST['add1'])){ ?>
    <dt>Additional Stop</dt>
    <dd><?php echo $_POST['add1']; ?></dd> // No need to have condition here then.
<?php } ?>

Just write like this : 就像这样写:

if(isset($_POST['add1']) && !empty($_POST['add1'])){
    echo '<dt>Additional Stop</dt>';
    echo '<dd>'.$_POST['add1'].'</dd>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM