I've been using an anti-spam contact form for a while now and I've adapted it to write to a database, send a page url...etc.
This time I'm using it just as a contact form, but want to highlight empty fields which I have partially working. (issue is not showing highlighted field when filled out and submit is hit again)
I found this http://kalsey.com/simplified/form_errors/ but it is written a little differently and sparked some ideas.
Start of the checking in my form...general statement about empty fields...
Then each field is check more in depth like so...PHP Code:if (isset($c['submit'])) {
if (empty($c['recipient']) || empty($c['firstname']) || empty($c['lastname']) || empty($c['email']) || empty($c['contact_method'])|| empty($c['comments'])) {
$error_msg .= "All fields marked with an * are required. \n";
....email...other fields....etc.PHP Code:} elseif (strlen($c['firstname']) > 10) {
$error_msg .= "The name field is limited at 10 characters. Your first name will do. \n";
Now, how this ties into the form field itself...
I tried to check against the field in 2 ways with && AND but I kept getting BOOLEAN errors. ex. if (!empty($error_msg['firstname'])) && something elsePHP Code:<input name="firstname" type="text" <?php if (!empty($error_msg['firstname'])) echo 'class="req"'; ?> id="firstname" value="<?php get_data("firstname"); ?>" size="30">
<?php if (!empty($error_msg['firstname'])) echo 'class="req"'; ?>
does it's job to echo class="req" which highlights the field, but my problem is returning a false if the field does get filled out to not show the field highlighted class like there is an error.
basically...
field empty - highlighted -- user goes back and fills it in and submits but has another error..the first error they fixed isn't highlighted anymore.
Does anyone have any ideas to change <?php if (!empty($error_msg['firstname'])) echo 'class="req"'; ?> to not show the class if the field is ok? Thank you!



Reply With Quote
Bookmarks