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

From: uw
Date: Wed Apr 26 15:44:58 2000
Modified files:
      php-lib/php/form/form.inc
      php-lib/php/form/template_bridge.inc

Log message:
- bugfix in form->autoloadValues() to work on arrays and different
elname/name attributes of an element

Index: php-lib/php/form/form.inc
diff -u php-lib/php/form/form.inc:1.3 php-lib/php/form/form.inc:1.4
--- php-lib/php/form/form.inc:1.3 Tue Apr 18 13:56:29 2000
+++ php-lib/php/form/form.inc Wed Apr 26 15:44:57 2000
@@ -156,7 +156,7 @@
                 reset($this->elements);
                 while (list($elname, $value)=each($this->elements))
                         $data[$elname] = $this->getValue($elname);
-
+
                 return $data;
         } // end func getSessionHash
         
@@ -196,13 +196,41 @@
 
                 reset($ellist);
                 while (list($k, $name)=each($ellist)) {
- if (!isset($data[$name]))
- continue;
+ $el = $this->elements[$name];
+ $http_x_name = $el->name;
 
+ if ("]"==substr($http_x_name, -1) && $start=strpos($http_x_name, "[")) {
+
+ // The element name looks something like 'foo[x]'. We can't test
+ // "isset($http_x_vars["foo[x]"])", we have to translate it
+ // to: "isset($http_x_vars["foo"]["x"]);".
+
+ preg_match_all("/\[([a-zA-Z0-9_]+)\]/", $http_x_name, $regs, PREG_SET_ORDER);
+ $index = sprintf('["%s"]', substr($http_x_name, 0, $start));
+ reset($regs);
+ while (list($k, $match)=each($regs))
+ if ('"'!=substr($match[1], 1) && '"'!=substr($match[1], -1))
+ $index.= sprintf('["%s"]', $match[1]);
+
+ $code = sprintf('$ok = isset($data%s);', $index);
+ // If you script dies on this line, you've choosed an illegal element name
+ eval($code);
+ if (!$ok)
+ continue;
+
+ $code = sprintf('$value = $data%s;', $index);
+ eval($code);
+
+ } else {
+ if (!isset($data[$http_x_name]))
+ continue;
+ $value = $data[$http_x_name];
+ }
+
                         if (isset($this->elements[$name])) {
 
                                 $el = $this->elements[$name];
- $el->setValue($data[$name]);
+ $el->setValue($value);
                                 $this->elements[$name] = $el;
                                 
                         } else if (isset($this->radio_elements[$name])) {
@@ -211,7 +239,7 @@
                                 reset($elements);
                                 while (list($elname, $v)=each($elements)) {
                                         $el = $this->elements[$elname];
- $el->setValue($data[$name]);
+ $el->setValue($value);
                                         $this->elements[$elname] = $el;
                                 }
 
@@ -556,6 +584,7 @@
 
                 $of_objectname = "form_elements_".$of_objectname;
                 $el = new $of_objectname( $element_data,
+ $this->method,
                                                                                                                         $this->js_name, $this->js_mode,
                                                                                                                         $this->cr_html, $this->cr_js,
                                                                                                                         $this->cr,
Index: php-lib/php/form/template_bridge.inc
diff -u php-lib/php/form/template_bridge.inc:1.3 php-lib/php/form/template_bridge.inc:1.4
--- php-lib/php/form/template_bridge.inc:1.3 Wed Apr 26 11:16:21 2000
+++ php-lib/php/form/template_bridge.inc Wed Apr 26 15:44:57 2000
@@ -218,7 +218,6 @@
                 while (list($k, $data)=each($this->elements))
                         if ("form"==$data["type"])
                                 $session_hash[$data["name"]] = $this->form->getValue($data["name"]);
-
                 return $session_hash;
         } // end func getSessionHash()
         

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