VDaemon PHP Library | VDaemon Extension | Table of Contents

VDaemon Tutorial
Step 4 - Adding Validation Elements

Now you will learn how to add validation rules to the form. All validation is defined by the vlvalidator and vlgroup VDaemon custom tags. This tags has many attributes which allow you to define all of the common validation types as well as create custom validation logic. To learn all of the validator features please see the reference. In this tutorial the following types of validation are used:

- "required" is most common type. It indicates that a value must be entered in the input element for it to pass validation. Let's examine the first occurence of the "required" validator:
<vlvalidator name="NameReq" type="required" control="Name" errmsg="Name required">
The validator attributes shown above are common to all of the types of validators. Each validator must have a unique name (name="NameReq"). The validation type is defined by "type" attribute (type="required"). The "control" attribute specifies the input element to validate (control="Name"). Lastly, the "errmsg" attribute contains error message that will be displayed on the form page should the validation test for this vaildator fail.

- "email" validator is used to determine whether the value of the associated input element is a properly formatted E-mail address:
<vlvalidator type="email" name="Email" control="Email" errmsg="Invalid E-mail">

After adding validation elements your page source code should look as shown below.

<?php include('vdaemon/vdaemon.php'); ?>
<html>
<head>
<title>VDaemon Validation Sample</title>
<style type="text/css">
<!--
.default
{
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: bold
}
.defaultErr
{
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #FF0000
}
-->
</style>
</head>
<body>
<p class="default">Quick contact form.</p>
<form method="POST" name="QContact" runat="vdaemon" action="process.php">
  <table cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td width="100">
        Your Name:
      </td>
      <td width="200">
        <input name="Name" type="text" size="25">
        <vlvalidator name="NameReq" type="required" control="Name" errmsg="Name required">
      </td>
    </tr>
    <tr>
      <td width="100">
        Your E-mail:
      </td>
      <td width="200">
        <input type="text" name="Email" size="25">
        <vlvalidator name="EmailReq" type="required" control="Email" errmsg="E-mail required">
        <vlvalidator name="Email" type="email" control="Email" errmsg="Invalid E-mail">
      </td>
    </tr>
    <tr>
      <td colspan="2">
        Your Message/Question:
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <textarea name="Message" cols="40" rows="7" wrap="virtual"></textarea>
        <vlvalidator name="MessageReq" type="required" control="Message" errmsg="Message required">
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="submit" value="Send">
      </td>
    </tr>
  </table>
</form>
</body>
</html>

Continue to Step 5