我的代码是否在未从选择框中选择选项时显示错误
这是我的变量
$schanName = 'Please select an Option';
这是我的代码
if($_POST['thisfolder'] == 'default') {
echo $schanName;
return;
}
现在我的观点是如何在页面的任何位置显示此消息Please select a Option
?
因为我在if语句中有2个echo,而第二个如果我像这样放入div
<div ><?php echo $schanName; ?></div>
这不会起作用,它会在页面底部显示错误
编辑#2
不确定你们是否在阅读我的问题。
在我的页面上,我有一个带有选择框的表单
我在底部有这个
这是显示错误的div
<div ><?php echo $schanName; ?></div>
HERE is Form
<?php
$schanName = 'Please select a Channel';
if($_POST['thisfolder'] == 'default') {
echo $schanName;
return;
}
?>
在我的页面上就是这样的。我相信我的div放置没有问题
编辑#3整页
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div id="error"> i must display that error here</div>
<form class="s_submit" method="post">
<input class="t_box" type='text' name='filename' placeholder='File name'>
<button type="submit" class="btn btn-primary">submit</button>
</form>
<?php
$fNum = 'File name is Required';
if(empty($_POST['filename'])) {
echo $fNum;
return;
}
?>
</body>
</html>
答案 0 :(得分:0)
//thisfolder is empty or not set
if(empty($_POST['thisfolder']) {
echo $schanName;
}else {
//thisfolder is not empty
echo $_POST['thisfolder'];
}
答案 1 :(得分:0)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div id="error">
<?php
// not asked so it does not show an error when no form was submitted
if(isset($_POST['filename']) && empty($_POST['filename'])) {
echo 'File name is Required';
}
?>
</div>
<form class="s_submit" method="post">
<input class="t_box" type='text' name='filename' placeholder='File name'>
<button type="submit" class="btn btn-primary">submit</button>
</form>
</body>
</html>