You are here

function _msnf_form_submit in Multistep Nodeform 6

Custom submit handler for node form.

Block node creation until we are on the last step.

1 string reference to '_msnf_form_submit'
msnf_prepare_form_step in ./msnf.module
Function to prepare the current form step and to alter the node form.

File

./msnf.module, line 311
Main functions for module "Multistep Nodeform".

Code

function _msnf_form_submit($form, &$form_state) {

  // Load necessary functions for form steps.
  module_load_include('inc', 'msnf', 'includes/msnf.steps');

  // Get node type and current step.
  $type = $form_state['values']['type'];
  $current_step = _msnf_form_step_get_current($form_state) - 1;

  // Get a sorted list of all steps for this content type.
  $steps = msnf_steps($type, TRUE);
  if (count($steps) == 0) {

    // No steps defined.
    return;
  }
  if (!isset($steps[$current_step])) {
    drupal_set_message(t('Invalid step index "%current_step".', array(
      '%current_step' => $current_step,
    )), 'error');
    return;
  }

  // Current step.
  $step = $steps[$current_step];

  // Is this the last available step?
  if ($form_state['storage']['step'] == count($steps)) {

    // Clear storage to avoid automatic form rebuild.
    $form_state['storage'] = NULL;

    // Prevent double submitting node (we are last submit callback).
    unset($form['#submit']);

    // Create a node.
    node_form_submit($form, $form_state);
  }
}