VDaemon PHP Library | VDaemon Extension | Table of Contents
During this step you will study how to display error messages to the user. To accomplish this, vlsummary and vllabel VDaemon custom tags are used.
The vlsummary custom tag allows you to summarize the error messages from all 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:
<vlsummary class="defaultErr" headertext="Error(s) found:">
You may need to display an error message or highlight some text at or near the location
where an input validation error has occurred. The "vllabel" custom tag provides
you an easy yet powerful way to accomplish this. Each "vllabel" tag
references one or more vlvalidator tags. The logical
"AND" is applied to the vlvalidator references to determine how the "vllabel" tag
will be rendered on
a
page.
For instance, the state of the following vllabel depends on the "EmailReq" and "Email" validators
that you created on step 4:
<vllabel validators="EmailReq,Email" class="default" errclass="defaultErr">Your
E-mail:</vllabel>
After adding error messaging elements to your page, the source code should appear 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"> <vlsummary class="defaultErr" headertext="Error(s) found:"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td width="100"> <vllabel class="default" errclass="defaultErr" validators="NameReq">Your Name:</vllabel> </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"> <vllabel class="default" errclass="defaultErr" validators="EmailReq,Email">Your E-mail:</vllabel> </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"> <vllabel class="default" errclass="defaultErr" validators="MessageReq">Your Message/Question:</vllabel> </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 6