You are here

function webform_conditionals_form_add in Webform 7.4

Submit handler for webform_conditionals_form(). Add an additional choice.

1 string reference to 'webform_conditionals_form_add'
webform_conditionals_form in includes/webform.conditionals.inc
Form builder; Provide the form for adding conditionals to a webform node.

File

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

Code

function webform_conditionals_form_add($form, &$form_state) {

  // Build a default new conditional.
  unset($form_state['values']['conditionals']['new']);
  $weight = count($form_state['values']['conditionals']) > 10 ? -count($form_state['values']['conditionals']) : -10;
  foreach ($form_state['values']['conditionals'] as $key => $conditional) {
    $weight = max($weight, $conditional['weight']);
  }

  // Add the conditional to form state and rebuild the form.
  $form_state['values']['conditionals'][] = array(
    'rules' => array(
      array(
        'source_type' => 'component',
        'source' => NULL,
        'operator' => NULL,
        'value' => NULL,
      ),
    ),
    'andor' => 'and',
    'actions' => array(
      array(
        'target_type' => 'component',
        'target' => NULL,
        'invert' => NULL,
        'action' => NULL,
        'argument' => NULL,
      ),
    ),
    'weight' => $weight + 1,
  );
  $form_state['rebuild'] = TRUE;
}