[PHPLIB-DEV] cvs commit From: uw (phplib-dev <email protected>)
Date: 04/17/00

From: uw
Date: Mon Apr 17 11:23:11 2000
Added files:
      php-lib/pages/form/index.php3

Modified files:
      php-lib/pages/form/example_form.inc

Log message:
example_form.inc:
- added some comments
- renamed class from my_form to example_form

index.php3:
- example on how to use form

Index: php-lib/pages/form/example_form.inc
diff -u php-lib/pages/form/example_form.inc:1.1 php-lib/pages/form/example_form.inc:1.2
--- php-lib/pages/form/example_form.inc:1.1 Thu Apr 13 15:04:16 2000
+++ php-lib/pages/form/example_form.inc Mon Apr 17 11:22:40 2000
@@ -1,16 +1,21 @@
 <?php
-class my_form extends new_form {
-
- function my_form($js_mode="weak", $showerror="", $haltonerror="") {
- return $this->new_form($js_mode, $showerror, $haltonerror);
- }
-
+// This is your form definition. It's a class extending form which
+// provides a method Init and optionally custom validators.
+//
+// - requiered form definition: void Init(void)
+// - optional custom validators: void Example_Validator(void)
+//
+class example_form extends form {
         
+ // define/build the form
         function Init() {
                 
+ // set the default size (text, textarea)
                 $this->setSize(20);
+ // set the default maxlength (text, textarea)
                 $this->setMaxlength(100);
                 
+ // define elements
                 $this->addElement( array (
                                                                                                                                         "name" => "pass",
                                                                                                                                         "type" => "password",
@@ -30,7 +35,7 @@
                 $this->addElement( array (
                                                                                                                                         "name" => "numbers",
                                                                                                                                         "type" => "text",
- "frozen" => true,
+ "frozen" => false,
                                                                                                                                         
                                                                                                                                         "valid_e" => "Only numbers are allowed, no other characters.",
                                                                                                                                         "valid_regex" => "[0-9]+",
@@ -58,7 +63,7 @@
                 $this->addElement( array (
                                                                                                                                         "name" => "textarea",
                                                                                                                                         "type" => "textarea",
- "frozen" => true,
+ "frozen" => false,
                                                                                                                                         "value" => "I wish the sun would shine.",
                                                                                                                                         "cols" => 40,
                                                                                                                                         "rows" => 2,
@@ -85,7 +90,7 @@
                                                                                                                                         "minlength" => 1,
                                                                                                                                         "length_e" => "You must provide a file.",
                                                                                                                                         
- "valid_regex" => "\.[html|htm]$",
+ "valid_regex" => "[html|htm]$",
                                                                                                                                         "valid_icase" => false,
                                                                                                                                         "valid_e" => "I'm afraid the filetype is incorrect. It's not a HTML File, is it?"
                                                                                                                                         
@@ -134,9 +139,12 @@
                                                                                                                                         "intro" => array ( "-1" => "Custom validators..."),
                                                                                                                                         
                                                                                                                                         "size" => 1,
- "frozen" => true,
+ "frozen" => false,
                                                                                                                                         "multiple" => false,
- "validator" => "dependenciesTest5"
+
+ // bind a custom validator on this element -
+ // don't forget to write a method void DependencieValidator(void)
+ "validator" => "DependencieValidator"
                                                                                                                         )
                                                                                         );
 
@@ -334,20 +342,35 @@
                                                                                                                                         
                                                                                                                                         "frozen" => false
                                                                                                                         )
- );
- #$this->introspection("FORM");
+ );
+
+ // autoload the form with HTTP_[POST|GET]_VARS
+ $this->autoloadValues();
+
+ // All the new form classes have a method that dumps datastructures
+ // of objects and arrays. Use this function while debugging to get
+ // an idea of the internal datastructes
+ // $this->introspection("FORMS");
+
         } // end func Init
         
- function dependenciesTest5() {
+ // Custom Validator
+ // The custom validator gets called before the default validators start
+ // working. The custom validator has access to the values of all form
+ // elements, sets errors and or turns the default validation of elements on/off
+ function DependencieValidator() {
         
+ // get the value of the element dependencits
                 $value = $this->getValue("dependencies");
                 
                 switch ($value) {
                         case 1:
+ // don't validate the element pass
                                 $this->ValidationOff( "pass" );
                                 break;
                                 
                         case 5:
+ // don't validate (all events of) pass, numbers, secret_numbers
                                 $ellist = array( "pass" => "all",
                                                                                                         "numbers" => "all",
                                                                                                         "secret_numbers" => "all"
@@ -356,6 +379,9 @@
                                 break;
                                                                                                                                                         
                         case 7:
+ // don't care on:
+ // - valid_e/valid_regexp of the element textarea
+ // - length_e/minlength/maxlength of the element pass
                                 $ellist = array(
                                                                                                         "textarea" => "valid",
                                                                                                         "pass" => "length"
@@ -364,8 +390,11 @@
                                 break;
                 }
                 
+ // creates a error message
+ // $this->setValidationError( "dependencies",
+
                 #$this->introspection($this->elements);
         } // end func dependenciesdependencies
         
-} // end class my_form
+} // end class example_form
 ?>

-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.