How do I validate user input in FormMail?

Tags mail code
This article details how to validate user input in FormMail.

In this example, FormMail is configured to validate user input. View demo.


<head><title>Just testing</title></head>
  <form method="post" action="">
  <h1>Example of FormMail 3.0</h1>

This example shows the use of input validation.<br>
This must be nonnull: <input type="text" name="nonnull"><br>
This should be a NetID: <input type="text" name="NetID"><br>
This should be an email address: <input type="text" name="email"><br>
This should be a phonenumber with 5 digits:
<input type="text" name="phone5"><br>

This should be a phonenumber with 10 digits:
<input type="text" name="phone10"><br>

This should be just digits:
<input type="text" name="digits"><br>

This input is not checked:
<input type="text" name="stuff2"><br>

<input type="submit" value="Submit the form">

Configuration file

<!DOCTYPE form SYSTEM 'FormMail-3.0.dtd'>
<form name="example1" >

 <!-- List all the fields needing server-side validation -->

<validate name="nonnull" public="The nonnull field"        vtype="nonnull">
<validate name="NetID"   public="The NetID field"          vtype="NetID">
<validate name="phone5"  public="The 5 digit phone field"  vtype="phone5">
<validate name="phone10" public="The 10 digit phone field" vtype="phone10">
<validate name="digits"  public="The digits field"         vtype="digits">
<validate name="email"   public="The email field"          vtype="email">

 <!-- This prevents any mail being sent for this example -->

<mail name="mail2" nomail>

 <!-- Here's the html response when all input is valid
      Note that the full html page is generated, including
      the <html>...</html> tags

<response name="r0" >
<h1> Thank You for Submitting your Info</h1>
The nonnull field was: $nonnull<br>
The email field was: $email<br>
The NetID field was: $NetID<br>
The 5 digit phone field was: $phone5<br>
The 10 digit phone field was: $phone10<br>
The digits field was: $digits<br>

 <!-- This response only kicks in if $stuff2  (ie the
    value for the field that wasn't checked) is not blank -->

<response name="r1" if="$stuff2" >
The unchecked field was filled in and is: $stuff2<br>

 <!-- And finally, the end!  -->

<response name="r2" >
  The date is $fm_date.<br>



Article ID: 690
Fri 1/15/21 5:57 PM
Wed 6/9/21 9:49 AM