| [ Index ] |
PHP Cross Reference of Web Application Component Toolkit |
[Summary view] [Print] [Text view]
1 <?php 2 require '../load_wact.php'; 3 4 require_once WACT_ROOT . 'controller/controller.inc.php'; 5 require_once WACT_ROOT . 'controller/form.inc.php'; 6 require_once WACT_ROOT . 'validation/rules/match.inc.php'; 7 require_once WACT_ROOT . 'validation/rules/member.inc.php'; 8 9 /* 10 * This example demonstrates some advanced validation techniques 11 * We dont use handles for validation rules in this example, which 12 * is more standard. 13 */ 14 15 class myListener { 16 17 /* 18 * We have to set an initial value for the radio buttons 19 */ 20 function load(&$source, &$request, &$responseModel) { 21 $responseModel->set('frequency', 'occasionally'); 22 } 23 24 /* 25 * Trigger our thank you page when a valid submission is made 26 */ 27 function register(&$source, &$request, &$responseModel) { 28 if ($responseModel->isValid()) { 29 return 'success'; 30 } 31 } 32 33 } 34 35 $Form =& new FormController(); 36 $Form->addChild('register', new ButtonController(new StaticDelegate('myListener', 'register'))); 37 $Form->setDefaultChild('register'); 38 39 $Form->registerOnLoadListener(new StaticDelegate('myListener', 'load')); 40 41 // ordinary validation rules 42 $Form->addRule(new RequiredRule('username')); 43 $Form->addRule(new RequiredRule('password')); 44 $Form->addRule(new RequiredRule('passwordconfirm')); 45 $Form->addRule(new SizeRangeRule("password", 6, 15)); 46 $Form->addRule(new SizeRangeRule("passwordconfirm", 6, 15)); 47 48 // Make sure password and confirmed password match 49 $Form->addRule(new MatchRule('password', 'passwordconfirm')); 50 51 // Set an alternate source for internationalizable error messages 52 // for this rule. This lets us override the standard messages 53 // that the rule will generate 54 $rule =& new RequiredRule('terms'); 55 $rule->setGroup('inputexample'); 56 $Form->addRule($rule); 57 58 // Double check our radio buttons to make sure that the value is valid. 59 // They only time these rules should ever fail is due to one of the following: 60 // a programming error 61 // an error in the HTML template 62 // garbled communications at the HTTP level 63 // a browser that does not follow the HTML specifications 64 // a hacking attempt. 65 $Form->addRule(new RequiredRule('frequency')); 66 $Form->addRule( 67 new MemberRule('Frequency', 68 array_flip(array('occasionally', 'regularly', 'excessive')))); 69 70 $Form->setDefaultView(new Handle('FormView', array('/input/input.html'))); 71 $Form->addView('success', new Handle('View', array('/input/thanks.html'))); 72 $Form->start(); 73 74 75 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Nov 28 19:36:09 2004 | Cross-referenced by PHPXref 0.5 |