我在网站上创建一个登录表单,在表单顶部创建一个警告框时会出现问题,该警告框应该在服务器端验证和用户输入清理后显示错误消息。问题是当页面加载时,它显示警告框,而我希望它只在显示错误消息时显示。请帮忙吗?
HTML PART
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="form">
<span class="info">
<?php
echo
$fNameErr;
$lNameErr;
$emailErr;
?>
</span>
<br>
<ul class="tab-group">
<li class="tab active"><a href="#signup">Sign Up</a></li>
<li class="tab"><a href="login.php">Log In</a></li>
</ul>
<div class="tab-content">
<h1>Sign Up for Free</h1>
<form action="signup.php" method="post" autocomplete="off">
<div class="top-row">
<div class="field-wrap">
<label>
<span class="req"></span>
</label>
<input placeholder="Firstname*" type="text" value="<?php echo $firstname;?>" required autocomplete="off" name='firstname' />
</div>
<div class="field-wrap">
<label>
<span class="req"></span>
</label>
<input placeholder="LastName*" type="text" value="<?php echo $lastname;?>" required autocomplete="off" name='lastname' />
</div>
</div>
<div class="field-wrap">
<label>
<span class="req"></span>
</label>
<input placeholder="Email Address*" type="email" value="<?php echo $email;?>" required autocomplete="off" name='email' />
</div>
<div class="field-wrap">
<label>
<span class="req"></span>
</label>
<input placeholder="Set A Password*" type="password"required autocomplete="off" name='password'/>
</div>
<button type="submit" class="button button-block" name="register">Register</button>
</form>
</div> <!-- /form -->
</div>
</body>
</html>
style.css页面
.info {
color: pink;
display: block;
text-align: center;
padding: 5px;
margin-top: -20px;
margin-bottom: 15px;
border: 1px solid red;
background: #66131c;
}
答案 0 :(得分:2)
my_buf[0]=UserRxBufferFS[0];
尝试将此更改为以下内容。让我知道它是怎么回事
<span class="info">
<?php
echo
$fNameErr;
$lNameErr;
$emailErr;
?>
</span>
答案 1 :(得分:1)
<?php
if(isset($fnameErr) || isset($lNameErr) || isset($emailErr)){
echo '<span class="info">';
echo $fNameErr;
echo $lNameErr;
echo $emailErr;
echo '</span>';
}
?>
试试这个。如果它不起作用,请向我们展示您的PHP代码
答案 2 :(得分:1)
我假设您只希望在这些变量具有某种值时显示,否则它们将为空白。在这种情况下,仅输出此HTML元素将非常容易。也许是这样的:
<?php if(isset($fnameErr) || isset($lNameErr) || isset($emailErr)){
echo
"<span class='info'>"
$fNameErr;
$lNameErr;
$emailErr;
"</span>";
} ?>