function _wizard_recursive_form_defaults(&$defaults, $form, $depth = array()) { if(is_array($form)) { // Recurse into each child element (ie. anything that's not '#something') foreach(element_children($form) as $key) { $new = $depth; $new[] = $key; $form[$key] = _wizard_recursive_form_defaults($defaults[$key],$form[$key], $new); } // Now see if we have any properties (ie. '#something'). If we do, then // set a default. if(element_properties($form)) { // Attempt to set a default value for this form element. Don't do this // if it's a file type element - it doesn't work, and we'll actually // risk putting an entire file into the form as a default the browser // will ignore. if($form['#type'] != 'file' && isset($defaults)) { // Check if the special wizard default value is set. This can be used // to override normal behaviour. If it's there, it's used in preference // to anything else. $default_value = NULL; if(isset($form['#wizard_default_value'])) { // Use this over anything else $default_value = $form['#wizard_default_value']; unset($form['#wizard_default_value']); } elseif(!is_array($defaults)) { // We can use the default we have from the user data $default_value = $defaults; } // We can work around a problem in Drupal 5.1 by frigging $_POST // for checkbox form elements. See http://drupal.org/node/144482 if(WIZARD_WORKAROUND_DRUAPL51_FAPI_BUG && $form['#type'] == 'checkbox' && isset($default_value)) { $code='$_POST[\'wizard\'][\'' . implode("']['", $depth) . "'] = '" . $default_value . "';"; eval($code); } $form['#default_value'] = $default_value; } // end of if is file } } return $form; }