How do I configure conditional validation with FormMail?

This article details how to configure conditional validation with FormMail.

This example demonstrates conditional validation with FormMail. Try a demo.

Form

<html>
<head><title>Just testing</title></head>
<body>
<form method="post" action="http://www.uic.edu/htbin/cgiwrap/bin/formmail/FormMail/depts/accc/forms/formmail/example-6.txt">
<h1>Example of FormMail 3.0</h1>
This example shows the use of <em>conditional</em> input validation.<br>
Input some text: <input type="text" name="nonnull"><br>
<input type=checkbox name=checktext value=yes>Check the text for nonnull value.
<hr>
<input type="submit" value="Submit the form">
</form>
</body>
</html>

Configuration file

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

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

<validate name="nonnull" public="The nonnull field"  vtype="nonnull" if="$checktext">

  
 <!-- 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" >
<![CDATA[
<html><head><title>Junk</title></head><body>
<h1> Thank You for Submitting your Info</h1>
The text field was: $nonnull<br>
</response>
]]>

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

<response name="r1" if="$checktext" >
<![CDATA[
The above text field was checked for nonnull value.<br>
 ]]>
</response>

<response name="r2" if="NOT $checktext" >
<![CDATA[
The above text field was <em>not</em> checked for nonnull value.<br>
 ]]>
</response>

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

<response name="r3" >
<![CDATA[
  The date is $fm_date.<br>
</body></html>
 ]]>
</response>


</form>