You are here

function webform_components_form_submit in Webform 6.2

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

File

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

Code

function webform_components_form_submit($form, &$form_state) {
  $node = node_load($form_state['values']['nid']);

  // Update all mandatory and weight values.
  foreach ($node->webform['components'] as $cid => $component) {
    if ($component['pid'] != $form_state['values']['components'][$cid]['pid'] || $component['weight'] != $form_state['values']['components'][$cid]['weight'] || $component['mandatory'] != $form_state['values']['components'][$cid]['mandatory'] || $component['email'] != $form_state['values']['components'][$cid]['email']) {
      $component['weight'] = $form_state['values']['components'][$cid]['weight'];
      $component['mandatory'] = $form_state['values']['components'][$cid]['mandatory'];
      $component['email'] = $form_state['values']['components'][$cid]['email'];
      $component['pid'] = $form_state['values']['components'][$cid]['pid'];
      $component['nid'] = $node->nid;
      webform_component_update($component);
    }
  }
  if (isset($_POST['op']) && $_POST['op'] == t('Publish')) {
    $node->status = 1;
    node_save($node);
    drupal_set_message(t('Your webform has been published.'));
    return 'node/' . $node->nid;
  }
  elseif (isset($_POST['op']) && $_POST['op'] == t('Add')) {
    $component = $form_state['values']['add'];
    $form_state['redirect'] = array(
      'node/' . $node->nid . '/edit/components/new/' . $component['type'],
      'name=' . urlencode($component['name']) . '&mandatory=' . $component['mandatory'] . '&email=' . $component['email'] . '&pid=' . $component['pid'] . '&weight=' . $component['weight'],
    );
  }
  else {
    drupal_set_message(t('The component positions and mandatory values have been updated.'));

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