我需要你的帮助.. 我正在尝试在表单出现错误时将文本框设为红色...
这就是我能做的。但是当我提交 fore 时,我在表单中得到一个 Undefined Index error_css
if (isset($_POST['submit'])) {
if (empty($_POST['username'])) {
$error_css='background-color:red';
}
表单
<label for="username">Username:</label>
<input id="username" type="text" value="<?php if(isset($_POST['username'])){ echo $_POST['username']; } ?>" name="username" title='Username' />
感谢您的宝贵时间...
最佳答案
尝试这样的事情:
<?php
$username = "";
$error_css = "";
if (isset($_POST['submit'])) {
if(isset($_POST['username']))
$username = $_POST['username'];
else
$error_css='background-color:red';
}
?>
<label for="username">Username:</label>
<input id="username" type="text" value="<?php echo $username; ?>" name="username" title='Username' style="<?php echo $error_css; ?>"/>
关于php - 当表单中发生错误时使文本框颜色为红色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10626160/