You are here

function webform_component_edit_form_submit in Webform 5.2

Same name and namespace in other branches
  1. 6.3 includes/webform.components.inc \webform_component_edit_form_submit()
  2. 6.2 webform_components.inc \webform_component_edit_form_submit()
  3. 7.4 includes/webform.components.inc \webform_component_edit_form_submit()
  4. 7.3 includes/webform.components.inc \webform_component_edit_form_submit()

File

./webform_components.inc, line 429
Webform module components handling.

Code

function webform_component_edit_form_submit($form_id, $form_values) {
  $node = node_load($form_values['nid']);

  // Remove empty extra values.
  if (is_array($form_values['extra'])) {
    foreach ($form_values['extra'] as $key => $value) {
      if ($value === '') {
        unset($form_values['extra'][$key]);
      }
    }
  }

  // Remove empty attribute values.
  if (is_array($form_values['extra']['attributes'])) {
    foreach ($form_values['extra']['attributes'] as $key => $value) {
      if ($value === '') {
        unset($form_values['extra']['attributes'][$key]);
      }
    }
  }
  if ($form_values['clone']) {
    drupal_set_message(t('Component %name cloned.', array(
      '%name' => $form_values['name'],
    )));
    webform_component_clone($node, $form_values);
  }
  elseif (!empty($form_values['cid'])) {
    drupal_set_message(t('Component %name updated.', array(
      '%name' => $form_values['name'],
    )));
    webform_component_update($form_values);
  }
  else {
    drupal_set_message(t('New component %name added.', array(
      '%name' => $form_values['name'],
    )));
    $cid = webform_component_insert($form_values);
  }

  // Since Webform components have been updated but the node itself has not
  // been saved, it is necessary to explicitly clear the cache to make sure
  // the updated webform is visible to anonymous users.
  cache_clear_all();
  return 'node/' . $form_values['nid'] . '/edit/components';
}