[PHPLIB-DEV] cvs commit From: uw (phplib-dev <email protected>)
Date: 12/02/99

From: uw
Date: Thu Dec 2 06:35:39 1999
Modified files:
      php-lib/php/of_file.inc
      php-lib/php/of_radio.inc
      php-lib/php/of_select.inc
      php-lib/php/of_text.inc
      php-lib/php/of_textarea.inc
      php-lib/php/oohforms.inc

Log message:
Removed the unnecessary previously committeted self_validate_php() function in of_text,
of_textarea.inc etc.

Added a new function ext_validate() to oohforms.inc. ext_validate is an
extended version of validate that does not stop after finding one error. All
elements are checked. The function returns an array with two values: $error_msg contains
all lenght_e, valid_e, etc. messages. $error_flag is indexed by the
element names: $error_flag["elname"] = "single error_msg".

Index: php-lib/php/of_file.inc
diff -u php-lib/php/of_file.inc:1.5 php-lib/php/of_file.inc:1.6
--- php-lib/php/of_file.inc:1.5 Thu Nov 25 15:59:15 1999
+++ php-lib/php/of_file.inc Thu Dec 2 06:35:07 1999
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1998 by Jay Bloodworth
  *
- * $Id: of_file.inc,v 1.5 1999/11/25 14:59:15 negro Exp $
+ * $Id: of_file.inc,v 1.6 1999/12/02 05:35:07 uw Exp $
  */
 
 class of_file extends of_element {
@@ -29,3 +29,4 @@
   }
 
 } // end FILE
+?>
\ No newline at end of file
Index: php-lib/php/of_radio.inc
diff -u php-lib/php/of_radio.inc:1.6 php-lib/php/of_radio.inc:1.7
--- php-lib/php/of_radio.inc:1.6 Thu Nov 25 15:59:15 1999
+++ php-lib/php/of_radio.inc Thu Dec 2 06:35:07 1999
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1998 by Jay Bloodworth
  *
- * $Id: of_radio.inc,v 1.6 1999/11/25 14:59:15 negro Exp $
+ * $Id: of_radio.inc,v 1.7 1999/12/02 05:35:07 uw Exp $
  */
 
 class of_radio extends of_element {
@@ -72,4 +72,4 @@
 
 } // end RADIO
 
-?>
+?>
\ No newline at end of file
Index: php-lib/php/of_select.inc
diff -u php-lib/php/of_select.inc:1.6 php-lib/php/of_select.inc:1.7
--- php-lib/php/of_select.inc:1.6 Thu Nov 25 15:59:15 1999
+++ php-lib/php/of_select.inc Thu Dec 2 06:35:07 1999
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1998 by Jay Bloodworth
  *
- * $Id: of_select.inc,v 1.6 1999/11/25 14:59:15 negro Exp $
+ * $Id: of_select.inc,v 1.7 1999/12/02 05:35:07 uw Exp $
  */
 
 class of_select extends of_element {
@@ -108,5 +108,4 @@
   }
 
 } // end SELECT
-
-?>
+?>
\ No newline at end of file
Index: php-lib/php/of_text.inc
diff -u php-lib/php/of_text.inc:1.8 php-lib/php/of_text.inc:1.9
--- php-lib/php/of_text.inc:1.8 Thu Nov 25 15:59:16 1999
+++ php-lib/php/of_text.inc Thu Dec 2 06:35:07 1999
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1998 by Jay Bloodworth
  *
- * $Id: of_text.inc,v 1.8 1999/11/25 14:59:16 negro Exp $
+ * $Id: of_text.inc,v 1.9 1999/12/02 05:35:07 uw Exp $
  */
 
 class of_text extends of_element {
@@ -101,36 +101,6 @@
     }
     return false;
   }
-
- function self_validate_php($val) {
-
- $php_code = "";
- if (!is_array($val)) $val = array($val);
- reset($val);
- while (list($k, $v)=each($val)) {
-
- if ($this->length_e) {
- $condition = "";
- if ($this->minlength) $condition.=sprintf("(strlen($%s)<%s) || ", $this->name, (int)$this->minlength);
- if ($this->maxlength) $condition.=sprintf("(strlen($%s)>%s) || ", $this->name, (int)$this->maxlength);
- if (""!=$condition) {
- $condition.="false";
- $php_code.= $this->generate_php($condition, $this->name, $this->title, $this->length_e);
- }
- }
-
- if ($this->valid_e) {
- $condition = "";
- if ($this->icase)
- $condition.= sprintf("(!eregi(\"%s\", \"$%s\"))", $this->valid_regex, $this->name);
- else
- $condition.= sprintf("(!ereg(\"%s\", \"$%s\"))", $this->valid_regex, $this->name);
- if (""!=$condition)
- $php_code.=$this->generate_php($condition, $this->name, $this->title, $this->valid_e);
- }
- }
- return $php_code;
- } // end func self_validate_php($val)
 
 } // end TEXT
-?>
+?>
\ No newline at end of file
Index: php-lib/php/of_textarea.inc
diff -u php-lib/php/of_textarea.inc:1.8 php-lib/php/of_textarea.inc:1.9
--- php-lib/php/of_textarea.inc:1.8 Thu Nov 25 15:59:16 1999
+++ php-lib/php/of_textarea.inc Thu Dec 2 06:35:07 1999
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1998 by Jay Bloodworth
  *
- * $Id: of_textarea.inc,v 1.8 1999/11/25 14:59:16 negro Exp $
+ * $Id: of_textarea.inc,v 1.9 1999/12/02 05:35:07 uw Exp $
  */
 
 class of_textarea extends of_element {
@@ -42,26 +42,5 @@
     $count = 1;
     return $str;
   }
-
- function self_validate_php($val) {
-
- $php_code = "";
-
- if ($this->length_e) {
- if ($this->minlength) {
- $condition.=sprintf("(strlen($%s) < %s) ||", $this->name, (int)$this->minlength);
- } else if ($this->maxlength) {
- $condition.=sprintf("(strlen($%s) > %s) ||", $this->name, (int)$this->maxlength);
- }
- if (""!=$condition) {
- $condition.="false";
- $php_code.= $this->generate_php($condition, $this->name, $this->title, $this->length_e);
- }
- }
-
- return $php_code;
- } // end func self_validate_php
-
 } // end TEXTAREA
-
 ?>
Index: php-lib/php/oohforms.inc
diff -u php-lib/php/oohforms.inc:1.19 php-lib/php/oohforms.inc:1.20
--- php-lib/php/oohforms.inc:1.19 Thu Nov 18 00:47:42 1999
+++ php-lib/php/oohforms.inc Thu Dec 2 06:35:07 1999
@@ -5,7 +5,7 @@
  *
  * Copyright (c) 1998 by Jay Bloodworth
  *
- * $Id: oohforms.inc,v 1.19 1999/11/17 23:47:42 uw Exp $
+ * $Id: oohforms.inc,v 1.20 1999/12/02 05:35:07 uw Exp $
  */
 
 class of_element {
@@ -43,11 +43,7 @@
   function self_validate($val) {
     return false;
   }
-
- function self_validate_php($val) {
- return false;
- }
-
+
   function self_get_js($ndx_array) {
   }
   
@@ -77,10 +73,6 @@
       $this->$k = $v;
     }
   }
-
- function generate_php ($condition, $name, $title, $error) {
- return sprintf("if (%s) {\n\t$%s.=\"%s\\n\";\n\t$%s[\"%s\"] = array ( \"%s\", \"%s\");\n};\n", $condition, "error_msg", $error, "error_flag", $name, $title, $error);
- }
 
 } // end ELEMENT
 
@@ -337,32 +329,37 @@
     }
     return $default;
   }
-
- function php_validate($vallist="") {
+
+ /*
+ public: array ($error_msg, array $error_flag) = ext_validate ( mixed $default, mixed $vallist, string $delimiter )
+ serverside validate that gives you an array indexed by the elementname
+ */
+ function ext_validate($default=false,$vallist="", $delimiter="\n" ) {
         
- if ($vallist) {
- if (!is_array($vallist)) $vallist = array($vallist);
- reset($vallist);
- $elrec = $this->elements[current($vallist)];
- } else {
- reset($this->elements);
- $elrec = current($this->elements);
- }
+ // convert vallist to array in necessary
+ if (""!=$vallist && !is_array($vallist))
+ $vallist = array ($vallist);
                 
- $php_code = "";
- while ($elrec) {
- $el = $elrec["ob"];
- $php_code.=$el->self_validate_php($el->value);
- if ($vallist) {
- next($vallist);
- $elrec = $this->elements[current($vallist)];
- } else {
- next($this->elements);
- $elrec = current($this->elements);
+ // fallback to all elements
+ if (!is_array($vallist))
+ $vallist = $this->elements;
+
+ $error_flags = array();
+ $error_msg = "";
+
+ while (list($elname, $v)=each($vallist)) {
+ // does this element exist?
+ if (isset($this->elements[$elname])) {
+ $el = $this->elements[$elname]["ob"];
+ if ($res = $el->marshal_dispatch($this->method,"self_validate") ) {
+ $error_flags[$elname] = $res;
+ $error_msg.=$res.$delimiter;
+ } else
+ $error_flags[$elname] = $default;
                         }
                 }
- return $php_code;
- }
+ return array ($error_msg, $error_flags);
+ } // end func ext_validate
 
   function load_defaults($deflist="") {
     if ($deflist) {
@@ -415,5 +412,4 @@
 include($_PHPLIB["libdir"] . "of_checkbox.inc");
 include($_PHPLIB["libdir"] . "of_textarea.inc");
 include($_PHPLIB["libdir"] . "of_file.inc");
-
-?>
+?>
\ No newline at end of file

-
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.