Chapter 7. Interacting with Visitors

Introduction

Even though the Web is an interactive medium, you probably can’t (and don’t want to) be on hand all day, every day, to guide visitors through the site or respond to errors. Likewise, you probably don’t want to spend all your waking hours maintaining your site and personally leading each loyal visitor back to your site on a regular basis. Fortunately, there are many techniques for defending against unnecessary errors automatically. And when your site operates smoothly, you can focus on ways to get to know your visitors and build relationships with them with things like surveys, polls, webcasts, web chats, and webinars. In this chapter, I’ll go over some of the little details that make a web site visit successful and enjoyable.

7.1. Preventing Blank Form Fields

Problem

You need to make sure visitors to your site fill in all the required fields in your web site form.

Solution

Use the onBlur, onClick, or onSubmit JavaScript event handlers in your form to check for empty fields before the form data is sent to the server.

Discussion

A well-written PHP or CGI script will check the data it gets from a web form before it performs its actions on it. If required fields are missing, the script should show the user an error page, rather than saving incomplete information in a database.

Error-checking in your server-side scripts requires a hit on your web server and causes your user to wait; you can head off an unnecessary connection by checking form data ...

Get Web Site Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.