John_Saunders
09-11-2002, 11:16 PM
Can somebody tell me how I can change the background color of a form field when a user tries so submit a form and enters an incorrect value or leaves it blank?
I just need to know how to change the style of the incorrect fields. I would think it would be something like this:
<input name="name" type="text" size="25" value="<?php if (isset($_POST['name'])) { echo htmlChars($_POST['name']); } ?>" <?php if (isset($error)) { echo "class=\"highlight\""; } ?>>
Not only can I not get the class to show up when an error is made but I'm not sure how to get it to show up in the correct form field of the error the visitor made.
Here's the code that pertains to the error checking in my script. It currently just has a section in my page where a list of errors are displayed.
<?php
// Require name
if (empty($_POST['name'])) {
$error .= '<br><span class="error">You must enter your name.</span>';
}
// Require a valid e-mail address
if (!isEmail(stripData($_POST['email']))) {
$error .= '<br><span class="error">You must enter a valid e-mail address.</span>';
}
// Require a value for the inquiry field
if (empty($_POST['inquiry'])) {
$error .= '<br><span class="error">You must enter a value for the comment/question field.</span>';
}
?>
section in page that shows error:
<?php if (isset($error)) { echo "<span class=\"error\">The following errors were found:</span><br>"; } ?>
<?php if (isset($error)) { echo $error; } ?>
Any ideas? Would something like this work?
<?php
// Require name
if (empty($_POST['name'])) {
$error .= '<br><span class="error">You must enter your name.</span>';
}
else if () {
$error2 .='class="highlight"';
}
?>
Then in down in my form in the input tag add something like:
<?php if (isset($error)) { echo $error2; } ?>
John
I just need to know how to change the style of the incorrect fields. I would think it would be something like this:
<input name="name" type="text" size="25" value="<?php if (isset($_POST['name'])) { echo htmlChars($_POST['name']); } ?>" <?php if (isset($error)) { echo "class=\"highlight\""; } ?>>
Not only can I not get the class to show up when an error is made but I'm not sure how to get it to show up in the correct form field of the error the visitor made.
Here's the code that pertains to the error checking in my script. It currently just has a section in my page where a list of errors are displayed.
<?php
// Require name
if (empty($_POST['name'])) {
$error .= '<br><span class="error">You must enter your name.</span>';
}
// Require a valid e-mail address
if (!isEmail(stripData($_POST['email']))) {
$error .= '<br><span class="error">You must enter a valid e-mail address.</span>';
}
// Require a value for the inquiry field
if (empty($_POST['inquiry'])) {
$error .= '<br><span class="error">You must enter a value for the comment/question field.</span>';
}
?>
section in page that shows error:
<?php if (isset($error)) { echo "<span class=\"error\">The following errors were found:</span><br>"; } ?>
<?php if (isset($error)) { echo $error; } ?>
Any ideas? Would something like this work?
<?php
// Require name
if (empty($_POST['name'])) {
$error .= '<br><span class="error">You must enter your name.</span>';
}
else if () {
$error2 .='class="highlight"';
}
?>
Then in down in my form in the input tag add something like:
<?php if (isset($error)) { echo $error2; } ?>
John