====== WACT Form Validation ====== [[Form validation]] in WACT is accomplished by adding validation rules to a [[controller:form|form controller]]. Generating output based on invalid form input is accomplished by using the [[tag:form:errorsummary|ErrorSummary tag]] and a view that registers validation errors with a given form, typically a [[view:form|FormView]]. Generally, client side form validation performs the validation rules in the executing client //before// the data is sent to the server. Conversely, server side form validation checks the data immediately as it is received by the server, and before any additonal processing is allowed to occur. FormComponent provides a powerful API for dealing with errors, allowing errors to be displayed alongside form fields where the error occurred. See the [[wact:examples]] for more examples. ===== 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 [[view:form|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 [[tag:form:errorsummary|ErrorSummary tag]]. ...
  • {$ErrorMessage}
:
:
:
...
===== Validation Rules ===== Please see the [[wact:api:validation:rule:catalog|WACT Validation Rules catalog]] for a list of validation rules. ===== Additional Information ===== * [[tag:form:errorsummary|ErrorSummary tag]] * [[wact:examples|WACT examples]] * [[wact:Controller architecture]]