diff -urp wizard/Wizard_Form.class.php /var/www/gatesdev/modules/contrib/wizard/Wizard_Form.class.php --- wizard/Wizard_Form.class.php 2007-06-22 20:58:02.000000000 -0700 +++ /var/www/gatesdev/modules/contrib/wizard/Wizard_Form.class.php 2007-08-23 12:02:53.000000000 -0700 @@ -25,8 +25,8 @@ class Wizard_Form { function get_current_page() { // Return cached value, if possible. if ($this->current_page > -1) return $this->current_page; - - $this->set_current_page(isset($this->fapi_form['#post']['page'])? (int) $this->fapi_form['#post']['page'] : 0); + + $this->set_current_page(isset($this->fapi_form['#post']['page'])? (int) $this->fapi_form['#post']['page'] : 1); return $this->current_page; } @@ -60,7 +60,7 @@ class Wizard_Form { function get_pages() { // Return cached value, if possible. if ($this->pages > -1) return $this->pages; - + // Sort FAPI form elements by weight first. if (!isset($this->fapi_form['#sorted'])) { uasort($this->fapi_form, '_element_sort'); @@ -77,17 +77,20 @@ class Wizard_Form { ) { $this->wizard_form['persistant'][$k] = &$this->fapi_form[$k]; continue; } // Separate form into pages by splitting at each CCK Wizard field. - if (isset($this->fapi_form[$k]['wizard'])) { $this->pages++; continue; } + if (isset($this->fapi_form[$k]['#wizard'])) { $this->pages++; continue; } // Skip the Preview and Submit buttons; these will be replaced later on. + // TODO: not sure if this logic below is accurate may need additional workaround + /* KO */ if ($this->pages > 0) { if (($k == 'preview' && isset($this->fapi_form[$k]['#type']) && $this->fapi_form[$k]['#type'] = 'button' && isset($this->fapi_form[$k]['#value']) && $this->fapi_form[$k]['#value'] = 'Preview') || ($k == 'submit' && isset($this->fapi_form[$k]['#type']) && $this->fapi_form[$k]['#type'] = 'button' && isset($this->fapi_form[$k]['#value']) && $this->fapi_form[$k]['#value'] = 'Submit') ) { continue; } + /* KO */ } // Assign remaining fields to the appropriate Wizard Form page. $this->wizard_form[$this->pages][$k] = &$this->fapi_form[$k]; } - + return $this->pages; } @@ -149,7 +152,7 @@ class Wizard_Form { $form['#redirect'] = FALSE; // Add Previous, Next, and/or Finish button(s). - if ($current_page > 0) { $form['previous'] = array('#type' => 'submit', '#value' => 'Previous', '#weight' => 40); } + if ($current_page > 1) { $form['previous'] = array('#type' => 'submit', '#value' => 'Previous', '#weight' => 40); } if ($current_page < $pages) { $form['next'] = array('#type' => 'submit', '#value' => 'Next', '#weight' => 45); } if ($current_page == $pages) { $form['finish'] = array('#type' => 'submit', '#value' => 'Finish', '#weight' => 50); } @@ -177,18 +180,21 @@ class Wizard_Form { function hide_submitted(&$form, &$form_values) { // for each $form_value that is not present in $form, // add its name and value to an array of hidden form elements - + $elements_only = $this->form_flatten($form); // remove properties and form fieldset elements $flattened_elements = $this->form_values_flatten($elements_only); // flatten hierarchy $flattened_values = $this->form_values_flatten($form_values); // flatten hierarchy $hidden_elements = $this->array_diff_key($flattened_values, $flattened_elements); // $form_values not present in $form - if (count($hidden_elements)) - foreach ($hidden_elements as $key => $value) { - $elements[$key] = array( - '#type' => 'hidden', - '#value' => $value, - ); + if (count($hidden_elements)) { + foreach ($hidden_elements as $key => $value) { + $elements[$key] = array( + '#type' => 'hidden', + '#value' => $value, + ); + } + } else { + $elements = array(); } return $elements; @@ -277,4 +283,4 @@ class Wizard_Form { return $elements; } -} \ No newline at end of file +} diff -urp wizard/wizard.module /var/www/gatesdev/modules/contrib/wizard/wizard.module --- wizard/wizard.module 2007-06-22 20:58:02.000000000 -0700 +++ /var/www/gatesdev/modules/contrib/wizard/wizard.module 2007-08-23 11:58:31.000000000 -0700 @@ -62,10 +62,12 @@ function wizard_widget($op, &$node, $fie switch ($op) { case 'form': $form = array(); - $form[$field['field_name']]['wizard'] = array( + $form[$field['field_name']] = array('#tree' => TRUE); + $form[$field['field_name']][0]['value'] = array( '#type' => 'hidden', '#default_value' => '', ); + $form[$field['field_name']]['#wizard'] = 1; return $form; break; } @@ -112,7 +114,7 @@ function wizard_menu($may_cache) { */ function wizard_form_alter($form_id, &$form) { // Only alter non-empty CCK forms. - if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && count($form)) { + if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && count($form) && (arg(4) != 'fields') && (arg(2) != 'edit')) { $wizard_form = new Wizard_Form($form); $wizard_form->alter_form(); } @@ -144,6 +146,7 @@ function wizard_submit($form_id, &$form_ // Stop short-circuiting real form #submit functions when on the last page. if ($form_values['op'] == 'Finish' && $current_page == $pages) { + _wizard_repair_form_values($form_values); unset($form['#redirect']); // TODO: this is set/unset in three different places; it could probably get away with just one. return; } @@ -163,4 +166,21 @@ function wizard_submit($form_id, &$form_ // Circumvent redirection $form['#redirect'] = FALSE; -} \ No newline at end of file +} + +/* + * Hack function to put form values back to drupal's expected format + */ +function _wizard_repair_form_values(&$form_values) { + foreach ($form_values as $key => $value) { + if (preg_match("/([^\[]*)\[([^\[]*)\](\[(.*)\])?/", $key, $matches)) { + $form_values[$matches[1]] = array(); + if ($matches[4]) { + $form_values[$matches[1]][$matches[2]] = array(); + $form_values[$matches[1]][$matches[2]][$matches[4]] = $value; + } else { + $form_values[$matches[1]][$matches[2]] = $value; + } + } + } +}