PHP setting text box cannot be empty

angryTom
Release: 2023-02-27 11:50:01
Original
5023 people have browsed it

PHP setting text box cannot be empty

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>
Copy after login

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>
Copy after login

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

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template