有人可以告诉我为什么该<?php echo $userPasswordError; ?>行不返回任何内容(空),而不是<div class="invalid-feedback">Too long.</div>当我使用以下代码输入包含超过 1 个字符的密码时?如果我改变这一行:$userPasswordError = '<div class="invalid-feedback">Too long.</div>';有了这个$userPasswordError = 'Too long.';,就可以了!输出是“太长”。<?php$user = $userPassword = '';$userError = $userInvalid = $userPasswordError = $userPasswordInvalid = '';$isvalidOrInvalidUser = $isvalidOrInvalidUserPassword = '';if ($_SERVER["REQUEST_METHOD"] == "POST") { // Verify username. if (!empty($_POST["user"])) { if (strlen($_POST["user"]) <= 32) { $user = $_POST["user"]; $userError = '<div class="valid-feedback">Correct.</div>'; $isvalidOrInvalidUser = 'is-valid'; } else { $userInvalid = $_POST["user"]; $userError = '<div class="invalid-feedback">Too long.</div>'; $isvalidOrInvalidUser = 'is-invalid'; } } else { $userError = '<div class="invalid-feedback">Please, add username.</div>'; $isvalidOrInvalidUser = 'is-invalid'; } // Verify password. if (!empty($_POST["userpassword"])) { if (strlen($_POST["userpassword"]) <= 1) { $userPassword = $_POST["userpassword"]; $userPasswordError = '<div class="valid-feedback">Correct.</div>'; $isvalidOrInvalidUserPassword = 'is-valid'; } else { $userPasswordInvalid = $_POST["userpassword"]; $userPasswordError = '<div class="invalid-feedback">Too long.</div>'; $isvalidOrInvalidUserPasword = 'is-invalid'; } } else { $userPasswordError = '<div class="invalid-feedback">Please, add password.</div>'; $isvalidOrInvalidUserPassword = 'is-invalid'; }}
1 回答
蝴蝶刀刀
TA贡献1801条经验 获得超8个赞
我终于知道为什么了。
$userPasswordError = '<div class="invalid-feedback">Too long.</div>';
$isvalidOrInvalidUserPasword = 'is-invalid';
的变量名isvalidOrInvalidUserPasword错误,应该是$isvalidOrInvalidUserPassword(缺少sat密码)。
如果输入没有 class is-invalid,错误消息将不可见!
希望这可以帮助!
- 1 回答
- 0 关注
- 130 浏览
添加回答
举报
0/150
提交
取消