On 26 Jan 99, Gerry Ott wrote:

> I have installed an Information Request Form on my clients site.  He wants
> to verify that certain fields of data are filled out and otherwise reject
> the submittal with a "missing info" comment if they aren't filled out.  In
> all the forms tutorials I have bookmarked, the issue of verification is
> not addressed.  Is this an html exercise or a server side cgi function? 
> In either case, can anyone point me to a site where forms verification is
> covered? 

It's a fairly straightforward scripting issue, can be handled in 
Javascript, Perl, ColdFusion and no doubt other languages/extensions.

If you use the Matt Wright's venerable formmail.pl to process your 
information requests, some basic validation comes built-in (at least 
in the version I use, 1.6) -- here's the salient bit:

***
    # For each required field defined in the form:                           #
    foreach $require (@Required) {

        # If the required field is the email field, the syntax of the email  #
        # address if checked to make sure it passes a valid syntax.          #
        if ($require eq 'email' && !&check_email($Config{$require})) {
            push(@error,$require);
        }

        # If it is a regular form field which has not been filled in or      #
        # filled in with a space, flag it as an error field.                 #
        elsif (!$Form{$require}) {
            push(@error,$require);
        }
    }

    # If any error fields have been found, send error message to the user.   #
    if (@error) { &error('missing_fields', @error) }
}

[snip, various sub-routines follow]

***

As you can see, nothing too complex here.  You can also do the same 
in Javascript, comme ca.  Following is complete code a working form 
that will check for a correctly entered e-mail address, and ensure 
that the user name field isn't empty. Should work in NS 2+ and MSIE 
3+:

***

 <html>
 <head>

 <title>Form Field Validation</title>

 <script language="JavaScript1.2">
 function isEmail(string) {
     if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
         return true;
     else
         return false;
 }

 function isProper(string) {
     if (string.search(/^\w+( \w+)?$/) != -1)
         return true;
     else
         return false;
 }
 
  function isReady(form) {
     if (isEmail(form.address.value) == false) {
         alert("Please enter a valid email address.");
         form.address.focus();
         return false;
     }
     if (isProper(form.username.value) == false) {
         alert("Please enter a valid username.");
         form.username.focus();
         return false;
     }
     return true;
 }
 
 //--></script>

 </head>

 <body>

 <form name="form_name" onsubmit="return isReady(this)">
 <table cellpadding=0 cellspacing=5 border=0><tr>
     <td align="left">Name:</td><td align="left"><input type="text" 
name="username"></td>
 </tr><tr>
     <td align="left">Email Address:</td><td align="left"><input type="text" 
name="address"></td>
 </tr><tr>
     <td><input type="submit" value="Submit"></td>
 </tr></table>
 </form>

 </body>
 </html>


-----------
Brent Eades, Almonte, Ontario
   E-mail: [EMAIL PROTECTED]
           [EMAIL PROTECTED]
   Web:    http://www.almonte.com/


____________________________________________________________________
--------------------------------------------------------------------
 Join The NEW Web Consultants Association FORUMS and CHAT:
   Register Today at: http://just4u.com/forums/
Web Consultants Web Site : http://just4u.com/webconsultants
   Give the Gift of Life This Year...
     Just4U Stop Smoking Support forum - helping smokers for
      over three years-tell a friend: http://just4u.com/forums/
          To get 500 Banner Ads for FREE
    go to http://www.linkbuddies.com/start.go?id=111261
---------------------------------------------------------------------

Reply via email to