Example
This example demonstrates a very simple use case of form validation. If validation doesn’t succeed, errors in red text will appear above the form controls.
signup.php
Dispatching controller, rule registration, and FormView.
$f = new FormController;
$f->addChild ('signup', new ButtonController (new StaticDelegate ('MailSignup', 'doSignup')));
/** these register rules to be checked upon form submission */
$f->addRule (new RequiredRule ('emailaddress'));
$f->addRule (new EmailRule ('emailaddress'));
$f->addRule (new RequiredRule ('mailtype'));
$f->addRule (new MemberRule ('mailtype', array_flip (array ('text', 'html'))));
$f->setDefaultView (new FormView ('/signupform.tpl.html'));
signupform.tpl.html
Template with form ErrorSummary tag.
...
<form method="POST" runat="server">
<errorsummary id="Summary">
<ul>
<list:item><li style="color: red;">{$ErrorMessage}</li></list:item>
</ul>
</errorsummary>
<label for="emailaddress">Email address</label>:
<input type="text" id="emailaddress" name="emailaddress"><br>
<label for="text">Plain text</label>:
<input id="text" name="mailtype" type="radio" value="text" checked><br>
<label for="html">HTML/formatted</label>:
<input id="html" name="mailtype" type="radio" value="html"><br>
<input type="submit" name="signup" value="Sign up">
</form>
...
Validation Rules
Please see the WACT Validation Rules catalog for a list of validation rules.