Your Ad Here

Simplified Form Errors

One of the most frustrating experiences on the Web is filling out forms. When mistakes are made, the user is often left guessing what they need to correct. We’ve taken an approach that shows the user in no uncertain terms what needs to be fixed.



The problem

Most forms require validation — checks to see that required fields have been filled out with the right information. But when a mistake was made, how do you let the user know? The approaches taken by many sites leave much to be desired.

  • Show the error messages on a different screen than the form. The user has to remember what was wrong when they go back to correct the form. Often when they go back, their form information is now missing.
  • Validate one field at a time. The user is told to fix their email address, but when they do, they’re told they also need to include their phone number.
  • List the errors at the top of the form. The user needs to scan the form matching the error with the appropriate fields.
  • Highlight the erroneous fields. The fields are often highlighted by changing the colors. Visitors with vision disabilities, with text browsers, or browsing from non-color devices have trouble figuring out which fields were wrong.
  • Show an icon or symbol next to the offending fields. The user isn’t expecting those icons, so they aren’t looking for them.

Simplified

Here’s how we simplified the error screen.

  • Show all of the errors on the form itself so the user doesn’t have to remember what the errors were in order to correct them.
  • Fill in the information the user has already entered so they don’t need to re-enter it.
  • Show the user a summary of everything that needs to be changed, right at the top of the form. This way, they don’t need to hunt through the form looking for error messages.
  • Show an error icon in the summary of errors and repeat that icon after each field that is filled in wrong. The user immediately associates the icon with the errors and can quickly find them in the form.
  • Surround the field with a colored box and repeat the error message right next to the field. The colored box draws attention to the missing information and the error text explains exactly why that field is highlighted. The user doesn’t need to look back up at the error list to understand why this field is marked.
  • Use three different indicators to show which fields have a problem. By not relying on images or color to show the problem fields, we’re increasing the odds that the messages are accessible to more people.

We’ve provided a demo of the simplified form. Go take a look.

The code

In addition to simply showing the form layout, we’ve also written up an example in PHP. The form validation is simple, but it’s easy to adapt this to your own validation needs or to another programming language like ASP or Perl.


<?php
// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
    
// Each time there’s an error, add an error message to the error array
    // using the field name as the key.
    
if ($_POST['name']=='')
        
$arrErrors['name'] = 'Please provide your name.';
    if (
$_POST['email']=='')
        
$arrErrors['email'] = 'A valid email address is required.';
    if (
$_POST['phone']=='')
        
$arrErrors['phone'] = 'Please provide your phone number.';
    if (
count($arrErrors) == 0) {
        
// If the error array is empty, there were no errors.
        // Insert form processing here.
    
} else {
        
// The error array had something in it. There was an error.
        // Start adding error text to an error string.
        
$strError = '<div class="formerror"><p><img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt="">Please check the following and try again:</p><ul>';
        
// Get each error and add it to the error string
        // as a list item.
        
foreach ($arrErrors as $error) {
            
$strError .= "<li>$error</li>";
        }
        
$strError .= '</ul></div>';
    }
}
?>

<style>
label {
  width: 80px;
  text-align: right;
  float: left;
}

.formerror {
  border: 1px solid red;
  background-color : #FFCCCC;
  width: auto;
  padding: 5px 0;
}

.errortext {
  padding-left: 80px;
  font: bold smaller sans-serif;
}
</style>

<?php echo $strError; ?>
<form method="post" action="<?php echo $PHP_SELF; ?>">
<!--
For every form field, we do the following...

Check to see if there’s an error message for this form field. If there is,
add the formerror class to the surrounding paragraph block. The formerror
class contains the highlighted box.

Insert the contents of what the user submitted bak into the form field.

Check again to see if this field has an error message. If it does, show
the error icon and the error message next to the field.
-->
<p<?php if (!empty($arrErrors['name'])) echo ' class="formerror"'; ?>>
    <label for="name">Name:</label>
    <input name="name" type="text" id="name" value="<?php echo $_POST['name'] ?>">
    <?php if (!empty($arrErrors['name'])) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['name'].'</span>'; ?>
</p>
<p<?php if (!empty($arrErrors['email'])) echo ' class="formerror"'; ?>>
    <label for="email">Email:</label>
    <input name="email" type="text" id="email" value="<?php echo $_POST['email'] ?>">
    <?php if (!empty($arrErrors['email'])) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['email'].'</span>'; ?>
</p>
<p<?php if (!empty($arrErrors['phone'])) echo ' class="formerror"'; ?>>
    <label for="phone">Phone:</label>
    <input name="phone" type="text" id="phone" value="<?php echo $_POST['phone'] ?>">
    <?php if (!empty($arrErrors['phone'])) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['phone'].'</span>'; ?>
</p>
<p>
    <input type="submit" name="Submit" value="Submit">
</p>
</form>

Richard Soderberg
July 27, 2003 3:20 PM

Looks remarkably similar to the error-handling I implemented at DataBuilt, way back when. We did server-side and client-side both — should still be up on the web!

Michael Alderete
July 29, 2003 9:00 AM

Thanks for the great example, both visual and the back-end code.

Even though a couple people have picked nits with the PHP you included, it’s quite valuable to be able to illustrate that it’s not a huge task to do your web forms this way, instead of the problem ways you describe at the beginning of the article.

The reason why people do forms the problem ways is because it’s easier, or it’s the first solution that comes to mind. Just showing them the outline of a better way is often enough to change their thinking. (OK, maybe I’m projecting here; it worked for me. ;-)

J.Shell
July 31, 2003 7:46 AM

Nice article. I’ve been using Zope and a product called “Formulator.” There are other kits like it out there for other languages/frameworks/servers. Basically - using Formulator (or something like it), you can design a form as smart widgets - instead of just an integer field, it can be an integer field with the range of 0 to 50. I like it because it takes care of both rendering (for most of my forms, I can just use a single loop to draw all of the fields) and validation.

Lately, I’ve been doing only one of the error displays that you’ve mentioned - displaying them up top, or displaying them next to the field. And I haven’t been doing the greatest job at highlighting. I’ll start applying both inline and uptop to my code from now on, and do the highlighting.

But I highly recommend looking into a Form Helper kit. ASP.NET has the concept built in, it seems. But for other systems - it’s very helpful to be able to describe and define a form, its widgets, validation, etc, in the same place - outside of the code that will be responsible for display and validation. My applications have become a lot stronger since moving to such a system (mostly because I’d tend to be lazy/stressed and often punt on manual validation as one of those “I’ll get back to it…” things).

Tom Davies
September 10, 2003 6:50 AM

The PEAR library comes with an HTMLQuickForm package that allows for some useful form validation and error displaying. So far I am pretty happy with it. If you are interested check it out at: http://pear.php.net/package/HTMLQuickForm

It should get you most of the way there.

Flemming Mahler
November 25, 2003 10:50 PM

Have you been past the Google AdSense login page recently (https://google.com/adsense/)? Try entering an invalid login and see what happens. While it isn’t exactly like the suggestion here, it is awfully close :)

These are the last 15 comments. Read all 25 comments here.

This discussion has been closed.

Lijit Search

Best Of

  • Simplified Form Errors One of the most frustrating experiences on the Web is filling out forms. When mistakes are made, the user is often left guessing what they need to correct. We've taken an approach that shows the user in no uncertain terms what needs to be fixed.
  • Where do the RSS ad startups fit in? Yahoo's RSS advertising service could spell trouble for pure-play RSS advertising services unless they adapt their business model.
  • Let it go Netscape 4 is six years old.
  • The importance of being good Starbucks is pulling CD burning stations from their stores. That says something interesting about their brand.
  • The mouse and me Not only is the mouse very destructive, but it's evaded all attempts to capture or kill it so far.
  • More of the best »

Recently Read

Get More

Subscribe | Archives

Recently

Cloud Reliability (Aug 12)
Would you like to take bets as to whether Amazon or Google have better reliability and safety than your local network service providers?
George Carlin (Jun 22)
"I'm always relieved when someone is delivering a eulogy and I realize I'm listening to it."
Business lessons from the Kitchen (Jun 9)
The Gordon Ramsay School of Business
Under The Radar twittering (Jun 3)
My live stream from Under the Radar
Measuring a CEO's mind (May 29)
Not everything that's important can be measured. Not everything that can be measured is important.
Golden 1: breaking customer expectations (May 25)
Take a potential new user and give them a poor signup experience, then call them a liar.
Sprout Test (May 7)
A test post for Sprout widgets.

Subscribe to this site's feed.

Elsewhere

Feed Crier
Get alerted by IM when your favorite web sites and feeds are updated.
SacStarts
The Sacramento technology startup community.
Pinewood Freak
Pinewood Derby tips and tricks
Del.icio.us
My tagstream at del.icio.us.
Waddlespot
My son's Club Penguin community. News, blogs, tips, and tricks.

Contact

Adam Kalsey

Mobile: 916.600.2497

Email: adam AT kalsey.com

AIM or Skype: akalsey

Resume

PGP Key

©1999-2008 Adam Kalsey.
Content management by Movable Type.