php setting text box cannot be empty
Usually we need to determine whether the information submitted by the user is empty. There are two methods: front-end js judgment and back-end server judgment.
For example, user form code
<form method="post" action="/check.php"> <input type="text" name="content" id="content" /> <input type="submit" value="提交" /> </form>
1. Use js to judge:
<form method="post" action="/check.php"> <!-- 表单改成下面这样 (加了一个 onsubmit) --> <form method="post" action="/check.php" onsubmit="return checkForm()"> <!-- 然后写一个简单的js判断一下 --> <script type="text/javascript"> function checkForm(){ var tag = false; var checkText = document.getElementById("content").value; if ( checkText == "" || checkText == null ){ alert("未输入"); }else{ alert("已输入"); tag = true; } return tag; } </script>
This js code should be placed where the form is file, or you can write it as a js file and import it
For example, remove the