Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php验证从html输入中删除数据_Php_Html_Validation - Fatal编程技术网

php验证从html输入中删除数据

php验证从html输入中删除数据,php,html,validation,Php,Html,Validation,我在使用PHP进行html输入验证时遇到了一些问题。验证本身正在工作。我有两个输入:姓名和办公室。 如果我在名称输入中输入一个值,但我没有在office输入中输入值,并单击“提交”按钮,则office输入的验证工作正常,但会清除/清空我在名称输入中输入的数据 我做错了什么 这是我的PHP验证: if (isset($_POST['submit'])){ $signatory_name = $_POST['sig_name']; $signtory_position = $_POS

我在使用PHP进行html输入验证时遇到了一些问题。验证本身正在工作。我有两个输入:姓名和办公室。 如果我在名称输入中输入一个值,但我没有在office输入中输入值,并单击“提交”按钮,则office输入的验证工作正常,但会清除/清空我在名称输入中输入的数据

我做错了什么

这是我的PHP验证:

if (isset($_POST['submit'])){
    $signatory_name = $_POST['sig_name'];
    $signtory_position = $_POST['sig_position'];

    if (!$_POST['sig_name']) {
            $errname='<div class="alert alert-danger">Sorry there was an error: Please Enter Your Name</div>';
        }

    if (!$_POST['sig_office']) {
            $erroffice='<div class="alert alert-danger">Sorry there was an error: Please Enter Your office</div>';
        }
}
if(isset($\u POST['submit'])){
$signature_name=$_POST['sig_name'];
$signtory_position=$_POST['sig_position'];
如果(!$\u POST['sig\u name']){
$errname='抱歉,出现错误:请输入您的姓名';
}
如果(!$\u POST['sig\u office']){
$erroffice='抱歉,出现错误:请输入您的办公室';
}
}
这是我的html代码

<form action="signatory.php" method="Post" role="form">
<input class="form-control " id="signatoryname" name="sig_name" placeholder="Name:" >
<input class="form-control " id="signatoryoffice" name="sig_office" placeholder="Office:">
</form>

正如斯库齐所说,您需要重新填充表单

大多数浏览器可能会帮你,但你不能依赖它

<form action="signatory.php" method="Post" role="form">
<input class="form-control " id="signatoryname" name="sig_name" placeholder="Name:" value="<?php echo !empty($_POST['sig_name']) ? $_POST['sig_name'] : ''; ?>">
<input class="form-control " id="signatoryoffice" name="sig_office" placeholder="Office:" value="<?php echo !empty($_POST['sig_office']) ? $_POST['sig_office'] : ''; ?>">
</form>


现在还不清楚您正在做什么或试图做什么,但以下是我的尝试:

首先:您应该知道,
if(!$\u POST['sig\u name']){
意味着如果指定的值为FALSE,您可能需要重新考虑这一点,并使用
empty()

验证输入后,需要使用提交的值重新填充表单-以下是一个示例:

<?php

    $errname = "";
    $erroffice= "";
    if (!empty($_POST)) {   // Only if there are POST values attached.

        $signatory_name = $_POST['sig_name'];
        $signtory_position = $_POST['sig_position'];

        if (empty($_POST['sig_name'])) {
            $errname='<div class="alert alert-danger">Sorry there was an error: Please Enter youre Name</div>';
        }

        if (empty($_POST['sig_office'])) {
             $erroffice='<div class="alert alert-danger">Sorry there was an error: Please Enter youre office</div>';
        }
        if (empty($errname) && empty($erroffice)) {

             //Do whatever you need with the validated inputs...

        } else {
            //Expose the alerts:
            echo $errname.$erroffice;
        }
    }
?>


<form method="POST" role="form">
    <input class="form-control" id="signatoryname" name="sig_name" value="<?php echo (isset($_POST['sig_name']))?$_POST['sig_name']:""; ?>" placeholder="Name:" />
    <input class="form-control" id="signatoryoffice" name="sig_office" value="<?php echo (isset($_POST['sig_office']))?$_POST['sig_office']:""; ?>" placeholder="Office:" />

    <!-- rest of your form and buttons -->
</form>


验证失败后如何重新填充表单尚不清楚。另外,请删除此代码段框。这并不是什么都不做,只是让人困惑。您不会收到未定义的索引通知,因为它围绕着一个!空的三元语句。如果它为空,则它将输出一个空字符串。