HTML code, form:
<code> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <input type="text" name="name" class="a1-input" placeholder="名字"> <div class="a1-btn-min"><button class="a1-btn waves-effect waves-light">YES</button></div> </form></code>
PHP code, verification:
<code><?php $name = ""; $name_str = mb_strlen($name,"UTF8"); if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { echo "<script>alert('你并没有写你的名字...')</script>"; } else if($name_str >= 10){ echo "<script>alert('这貌似不是一个名字吧~!')</script>"; } else{ $name = test_input($_POST["name"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?></code>
For the html and php code above, an empty variable named name is set, but later the character length filled in by the user in the form has to be obtained and verified.
However, when verifying the length, the length of the information filled in by the user cannot be verified. How to solve this problem?