? .svn ? conditional_elements.patch ? components/.svn ? tests/.svn ? translations/.svn Index: webform.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v retrieving revision 1.124.2.95 diff -u -p -r1.124.2.95 webform.module --- webform.module 27 Feb 2009 22:35:15 -0000 1.124.2.95 +++ webform.module 11 May 2009 15:38:10 -0000 @@ -1555,7 +1555,7 @@ function webform_client_form($form_state $microweight = 0.001; foreach ($component_tree['children'] as $cid => $component) { $component_value = isset($form_state['values']['submitted'][$component['form_key']]) ? $form_state['values']['submitted'][$component['form_key']] : NULL; - _webform_client_form_add_component($cid, $component, $component_value, $form['submitted'], $form, $submission, $page_num, $enabled); + _webform_client_form_add_component($cid, $component, $component_value, $form['submitted'], $form, $form_state, $submission, $page_num, $enabled); if (isset($form['submitted'][$component['form_key']])) { $form['submitted'][$component['form_key']]['#weight'] += $microweight; $microweight += 0.001; @@ -1592,7 +1592,20 @@ function webform_client_form($form_state return $form; } -function _webform_client_form_add_component($cid, $component, $component_value, &$parent_fieldset, &$form, $submission, $page_num, $enabled = FALSE) { +function _webform_client_form_add_component($cid, $component, $component_value, &$parent_fieldset, &$form, $form_state, $submission, $page_num, $enabled = FALSE) { + // Should we display this component? + $show_component = TRUE; + if (isset($component['extra']['cond_values']) && strlen(trim($component['extra']['cond_values'])) && $component['page_num'] == $page_num) { + $input_value = $form_state['values']['submitted'][$component['extra']['cond_component']]; + $test_values = array_map('trim', explode("\n", $component['extra']['cond_values'])); + $show_component = in_array($input_value, $test_values); + if ($component['extra']['cond_operator'] == '!=') { + $show_component = !$show_component; + } + if (!$show_component) { + return; + } + } // Load with submission information if necessary. if (!$enabled) { // This component is display only. @@ -1610,7 +1623,7 @@ function _webform_client_form_add_compon $parent_fieldset[$component['form_key']] = $display_function($data, $component, $enabled); } } - else { + else { $render_function = '_webform_render_'. $component['type']; if (function_exists($render_function)) { $parent_fieldset[$component['form_key']] = $render_function($component); // Call the component render function. @@ -1636,7 +1649,7 @@ function _webform_client_form_add_compon $microweight = 0.001; foreach ($component['children'] as $scid => $subcomponent) { $subcomponent_value = isset($component_value[$subcomponent['form_key']]) ? $component_value[$subcomponent['form_key']] : NULL; - _webform_client_form_add_component($scid, $subcomponent, $subcomponent_value, $parent_fieldset[$component['form_key']], $form, $submission, $page_num, $enabled); + _webform_client_form_add_component($scid, $subcomponent, $subcomponent_value, $parent_fieldset[$component['form_key']], $form, $form_state, $submission, $page_num, $enabled); $parent_fieldset[$component['form_key']][$subcomponent['form_key']]['#weight'] += $microweight; $microweight += 0.001; } Index: webform_components.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform_components.inc,v retrieving revision 1.9.2.28 diff -u -p -r1.9.2.28 webform_components.inc --- webform_components.inc 14 Feb 2009 19:57:38 -0000 1.9.2.28 +++ webform_components.inc 11 May 2009 15:38:10 -0000 @@ -367,6 +367,71 @@ function webform_component_edit_form($fo '#weight' => 4, ); + // Add conditional fields. + if ($component['type'] != 'pagebreak') { + $component_options = array(); + $counter = 0; + $last_pagebreak_slice = 0; + foreach ($node->webform['components'] as $cid => $test_component) { + // Only components before the pagebreak can be considered. + if ($test_component['name'] == $component['name']) { + break; + } + if ($test_component['type'] == 'pagebreak') { + $last_pagebreak_slice = $counter; + } + else { + $counter++; + $component_options[$test_component['form_key']] = $test_component['name']; + } + } + $component_options = array_slice($component_options, 0, $last_pagebreak_slice, TRUE); + $form['advanced']['conditional'] = array( + '#weight' => 5, + '#type' => 'fieldset', + '#title' => t('Display Rules'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => t('Create a rule to control whether or not to show this form element.'), + '#tree' => FALSE, + ); + $form['advanced']['conditional']['extra'] = array( + '#tree' => TRUE, + ); + $form['advanced']['conditional']['extra']['cond_component'] = array( + '#type' => 'select', + '#title' => t('Component'), + '#options' => $component_options, + '#description' => t('Select another component to decide whether to show or hide this component. You can only select components occurring before the most recent pagebreak.'), + '#default_value' => $component['extra']['cond_component'], + ); + $form['advanced']['conditional']['extra']['cond_operator'] = array( + '#type' => 'select', + '#title' => t('Operator'), + '#options' => array( + '=' => t('Is one of'), + '!=' => t('Is not one of') + ), + '#description' => t('Determines whether the list below is inclusive or exclusive.'), + '#default_value' => $component['extra']['cond_operator'], + ); + $form['advanced']['conditional']['extra']['cond_values'] = array( + '#type' => 'textarea', + '#title' => t('Values'), + '#description' => t('List values, one per line, that will trigger this action. If you leave this blank, this component will always display.'), + '#default_value' => $component['extra']['cond_values'], + ); + if (empty($component_options)) { + $form['advanced']['conditional']['extra']['cond_component']['#options'] = array(''); + $form['advanced']['conditional']['#description'] = t('You cannot set display options for a component appearing before the first pagebreak.'); + foreach ($form['advanced']['conditional']['extra'] as &$el) { + if (is_array($el)) { + $el['#disabled'] = TRUE; + } + } + } + } + // Add the fields specific to this component type: webform_load_components(); // Load all component types. $edit_function = '_webform_edit_'. $component['type'];