如题所述
PHP要判断表单元素的值是否为空,首先需要提交表单,然后根据name获取表单元素,判断是否为空即可。示例如下:<?phpif($_POST['sub']){//获取文本框的内容$content=$_POST['content'];if($content==""){echo "文本框内容为空!";}else{echo "文本框内容不为空!";}}?><html><head><title>演示</title></head><body><form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><input type="input" name="content"/><input type="submit" name="sub" value="提交"/></form></body></html>
温馨提示:答案为网友推荐,仅供参考