检查输入是否为空并且存在 - PHP

时间:2016-09-07 09:08:11

标签: php html sql web isset

我需要检查几个标签是否“不为空”。为此,我使用:

<input id="designation" type="text" size="12" disabled="disabled" />

然后,我需要在表格中放置几个​​<input ...>。所有这些都是用HTML创建的。我需要检查是否有任何标签是空的。

$erreurs = array();
// Check if the tag is not empty

if((empty($_POST['CodetERDF']))) {
    $erreurs[] = 'Veuillez renseigner le codet ERDF.';

    echo 'Veuillez renseigner le codet ERDF.';
}`

但我的代码似乎不起作用,我不明白为什么。

1 个答案:

答案 0 :(得分:2)

已禁用的输入未发布到服务器,因此它们永远不会显示在$_POST中。

同样适用于没有name属性的输入,因为name属性定义了$_POST中的关键字。

替代方案是将它们readonlyhidden或只是在会话变量中设置值/将其保留在服务器上。