You are here

function webform_conditional_element_remove in Webform 7.4

Submit handler for webform_conditional elements to remove a rule or action.

2 string references to 'webform_conditional_element_remove'
_webform_conditional_action_expand in includes/webform.conditionals.inc
Helper. Generate form elements for one action.
_webform_conditional_remove_expand in includes/webform.conditionals.inc
Helper. Generate the add_subconditional (+), add + or remove - button.

File

includes/webform.conditionals.inc, line 798
Form elements and menu callbacks to provide conditional handling in Webform.

Code

function webform_conditional_element_remove($form, &$form_state) {
  $button = $form_state['clicked_button'];
  $parents = $button['#parents'];
  $action = array_pop($parents);
  $rid = array_pop($parents);

  // Recurse through the form values until we find the root Webform conditional.
  $parent_values =& $form_state['values'];
  foreach ($parents as $key) {
    if (array_key_exists($key, $parent_values)) {
      $parent_values =& $parent_values[$key];
    }
  }
  switch ($parent_values[$rid]['source_type']) {
    case 'conditional_start':
      unset($parent_values[_webform_conditional_find_end($parent_values, $rid)]);
      break;
    case 'conditional_end':
      unset($parent_values[_webform_conditional_find_start($parent_values, $rid)]);
      break;
  }

  // Remove this rule or action from the list of conditionals.
  unset($parent_values[$rid]);
  $form_state['rebuild'] = TRUE;
}