You are here

function webform_component_edit_form_submit in Webform 6.3

Same name and namespace in other branches
  1. 5.2 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()

Submit handler for webform_component_edit_form().

File

includes/webform.components.inc, line 631
Webform module component handling.

Code

function webform_component_edit_form_submit($form, &$form_state) {

  // Ensure a webform record exists.
  $node = node_load($form_state['values']['nid']);
  webform_ensure_record($node);

  // Remove empty extra values.
  if (isset($form_state['values']['extra'])) {
    foreach ($form_state['values']['extra'] as $key => $value) {
      if ($value === '' && !isset($form['display'][$key]['#options'][''])) {
        unset($form_state['values']['extra'][$key]);
      }
    }
  }

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

  // 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();

  // Clear the entity cache if Entity Cache module is installed.
  if (module_exists('entitycache')) {
    cache_clear_all($node->nid, 'cache_entity_node');
  }
  $form_state['redirect'] = array(
    'node/' . $node->nid . '/webform/components',
    isset($cid) ? 'cid=' . $cid : '',
  );
}