不验证输入字段是否为空(PHP)

时间:2017-02-03 17:04:28

标签: php forms validation field

我有一个表单,其中包含需要验证的字段。但是,如果字段为空,我想跳过验证。此时,如果第一个用户将该字段留空,则将其留空的第二个用户将收到错误。我尝试过一些没有运气的逻辑操作。我可以帮忙吗?

编辑:这是一个工作职能:

function is_already_submitted($formName, $fieldName, $fieldValue) {
require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
$exp = new CFDBFormIterator();
$atts = array();
$atts['show'] = $fieldName;
$atts['filter'] = "$fieldName=$fieldValue";
$atts['unbuffered'] = 'true';
$exp->export($formName, $atts);
$found = false;
while ($row = $exp->nextRow()) {
    $found = true;
}
return $found;
}

function validate_registrationcode($result, $tag) {
$formName = 'Registration Form';
$fieldName = 'registrationcode';
$errorMessage = 'This code has already been used';
$name = $tag['name'];
if ($name == $fieldName) {
    if (!empty($_POST[$name]) && is_already_submitted($formName, $fieldName, $_POST[$name])) {
        $result->invalidate($tag, $errorMessage);
    }
}
return $result;
}

0 个答案:

没有答案