VDaemon PHP Library | VDaemon Extension | Table of Contents

VDaemon Tutorial
Displaying Error Messages

During this step we will add displaying of error messages to the page. To accomplish this, vlsummary and vllabel VDaemon custom tags are used.

The <vlsummary> custom tag allows us summarizing error messages from all invalid validators on a form in a single location. The error message displayed in the summary for each validator on the form is specified by the "errmsg" attribute of the corresponding validator. You can also specify a custom title in the heading section of the summary by setting the "headertext" attribute. Style of the entire summary is defined by "class" attribute:
<vlsummary class="error" headertext="Error(s) found:">

To highlight label near the "Name" input field we will use <vllabel> VDaemon custom tag. Each <vllabel> tag references one or more <vlvalidator> tags. The logical "AND" operation is applied to the <vlvalidator> states to determine how the <vllabel> tag will be rendered on a page. "errclass" attribute defines style of the label for error state. When VDaemon label is in error state it also can change style of the form input element. "for" attribute defines input element to change (you can reference input element "name" or "id" attribute). "cerrclass" attribute defines input element error class:
<vllabel errclass="error" validators="NameReq,NameRegExp" for="Name" cerrclass="controlerror">Enter your Name:</vllabel>

The last thing we must do is adding "error" and "controlerror" styles to the page:

After adding error messaging elements to your page, the source code should appear as shown below.

<?php include('vdaemon/vdaemon.php'); ?>
<html>
<head>
<title>Hello!</title>
<style type="text/css">
<!--
.error {
    color: #AA0000
}
.controlerror {
background-color: #ffffdd;
border: 1px solid #AA0000;
}
--> </style>
</head> <body> <p>Hello form.</p> <form method="POST" action="hello.php" id="Hello" runat="vdaemon"> <table cellpadding="2" cellspacing="0" border="0"> <tr> <td> <vllabel errclass="error" validators="NameReq,NameRegExp" for="Name" cerrclass="controlerror">Enter your Name:</vllabel> </td> <td> <input name="Name" type="text" size="25"> <vlvalidator name="NameReq" type="required" control="Name" errmsg="Name required"> <vlvalidator name="NameRegExp" type="regexp" control="Name" errmsg="Invalid Name" regexp="/^[a-z'\s]*$/i"> </td> <tr> <td colspan="2"> <input type="submit" value="Send"> </td> </tr> </table> <p><vlsummary class="error" headertext="Error(s) found:"></p> </form> </body> </html> <?php VDEnd(); ?>

Congratulations! Our form is ready. Run and test it.

We have completed the tutorial and I hope that you will enjoy using VDaemon for creating your own form validation solutions. Do not forget to visit the X-code web site from time to time for updates to the VDaemon family of products.