0
我有一個現有的表單。我想將輸入字段的邊框顏色從「紅色」更改爲「綠色」,並在「放置」字段下顯示錯誤消息。JQUERY-造型驗證
任何想法,和插件或者應用這種風格到錯誤信息的方式。 我目前使用下列內容:
.error {
background-color: #e86065;
color: black;
display:inline-block;
font: 0.5em;
height: 1.05em;
}
b#email{
margin-left: 30px;
}
input#pass1:invalid {
border: 1px solid red;
}
input#pass1:valid {
border: 1px solid green;
}
input#pass1:required{
background:transparent;
border-radius: 5px;
}
<form id="myform " class="Form" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" accept-charset="utf-8">
<!-- <div id="first">-->
<input type="email" id="email" name="email" placeholder="Email Address" value="" required >
<br>
<br>
<br>
<span class="error"><?php echo $c_emailErr; ?></span>
<br>
<figure>
<input class ="login-field" type="text" id="pass1" name="pass1" value="" placeholder="Password" maxlength="30" required>
<br>
<span class="error"><?php echo $c_pass1Err; ?></span>
<br>
<input class ="login-field" type="password" id="pass2" name="pass2" value="" placeholder=" Confirm password" maxlength="30" required><!--<span class="error"><?php //echo $c_pass2Err; ?></span>-->
<div id="messages"></div>
</figure>
<p class="remember_me">
</p>
<input type="submit" name="submit" value="Register" id="submit_button" class="btn btn-default">
<br>
</form>
PHP
<?php
$c_emailErr = $c_pass1Err = $c_pass2Err = "";
if (isset($_POST['submit'])) {
$c_email = $_POST['email'];
$c_pass1 = $_POST['pass1'];
$c_pass2 = $_POST['pass2'];
//Checking the email address
if (!filter_var($c_email, FILTER_VALIDATE_EMAIL) === false) {
} else {
$c_emailErr = ("<b> Email is not a valid email address</b>");
}
if (strlen($c_pass1) <= '8') {
$c_pass1Err = "<b>Your Password Must Contain At Least 8 Characters!</br>";
//check passwords
} elseif ($c_pass1 == $c_pass2) {
$q = "INSERT INTO Cus_Register(Cus_Email,Cus_Password,Cus_confirm_password) VALUES (?,?,?)";
$stmt = mysqli_prepare($dbc, $q);
mysqli_stmt_bind_param($stmt, 'sss', $c_email, $c_pass1, $c_pass2);
if ($q) {
echo "<script> alert('registration sucessful')</script>";
}
} else {
echo "<b>Oops! Your passwords do not </b>";
}
}
function clean_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
你的PHP要嗎? – divy3993
@ divy3993我真的不介意。 – jerneva