[Solar-svn] Revision 3156

pmjones at solarphp.com pmjones at solarphp.com
Wed May 14 08:58:12 CDT 2008


Solar_Form: [CHG] Now that date/time/timestamp are generally recognized as arrays, make an allowance for them as array values when populating the form.  Thanks, Kilbride, for the report.



Modified: trunk/Solar/Form.php
===================================================================
--- trunk/Solar/Form.php	2008-05-06 20:22:11 UTC (rev 3155)
+++ trunk/Solar/Form.php	2008-05-14 13:58:11 UTC (rev 3156)
@@ -928,49 +928,57 @@
     {
         // are we working with an array?
         if (is_array($src)) {
-            // is the array sequential?  check only the first key.
-            if (is_int(key($src))) {
-                // assign the sequential array to the element.
-                // this is for multiple-select options.
+            
+            // sequential arrays are generally multiple-select items.
+            // only check the first key on the array.
+            $is_sequential = is_int(key($src));
+            
+            // temporal values may also be expressed as arrays
+            $types = array('date', 'time', 'timestamp');
+            $is_temporal = isset($this->elements[$name]) &&
+                           in_array($this->elements[$name]['type'], $types);
+            
+            // retain value as-is, or descend through sub-elements?
+            if ($is_sequential || $is_temporal) {
+                // retain value as-is (no recursive descent)
                 $this->elements[$name]['value'] = $src;
             } else {
-                // not sequential. descend through each of the sub-elements.
+                // not sequential, not temporal. descend through each of the
+                // sub-elements.
                 foreach ($src as $key => $val) {
                     $sub = empty($name) ? $key : $name . "[$key]";
                     $this->_populate($val, $sub);
                 }
             }
-        } else {
-            // populate an element value, but only if it exists.
-            if (isset($this->elements[$name])) {
-                
-                // convenient reference
-                $elem =& $this->elements[$name];
-                
-                // do not populate certain elements, as this will
-                // reset their value inappropriately.
-                $skip = $name['type'] == 'submit' ||
-                        $name['type'] == 'button' ||
-                        $name['type'] == 'reset';
-                        
-                if ($skip) {
-                    return;
-                }
-                
-                // is this a multiple select?
-                $multiple = $elem['type'] == 'select' &&
-                            ! empty($elem['attribs']['multiple']);
-                
-                // set the value appropriately
-                if ($multiple && ! $src) {
-                    // empty on a multiple.  force it to an empty array.
-                    // (merely casting to array gets us an array with one
-                    // empty-string value.)
-                    $elem['value'] = array();
-                } else {
-                    $elem['value'] = $src;
-                }
+            
+        } elseif (isset($this->elements[$name])) {
+            
+            // convenient reference
+            $elem =& $this->elements[$name];
+            
+            // do not populate certain elements, as this will
+            // reset their value inappropriately.
+            $skip = $name['type'] == 'submit' ||
+                    $name['type'] == 'button' ||
+                    $name['type'] == 'reset';
+                    
+            if ($skip) {
+                return;
             }
+            
+            // is this a multiple select?
+            $multiple = $elem['type'] == 'select' &&
+                        ! empty($elem['attribs']['multiple']);
+            
+            // set the value appropriately
+            if ($multiple && ! $src) {
+                // empty on a multiple.  force it to an empty array.
+                // (merely casting to array gets us an array with one
+                // empty-string value.)
+                $elem['value'] = array();
+            } else {
+                $elem['value'] = $src;
+            }
         }
     }
     




More information about the Solar-svn mailing list