You are here

function batch_example_simple_form_submit in Examples for Developers 6

Same name and namespace in other branches
  1. 7 batch_example/batch_example.module \batch_example_simple_form_submit()

Submit handler for the form 'batch_example_simple_form'.

This submit handler will be called when the user clicks 'Go' in the form.

Related topics

File

batch_example/batch_example.module, line 98
This is an example outlining how a module can define batches.

Code

function batch_example_simple_form_submit($form, &$form_state) {

  // Dropdown will return 'batch_1' or 'batch_2'
  $values =& $form_state['values'];

  // Create a string with the function name 'batch_example_batch_1'
  // or 'batch_example_batch_2'
  $function = 'batch_example_' . $values['batch'];

  // Load the $batch variable with an array containing the details
  // of what to run
  $batch = $function();

  // Start the batch process running
  batch_set($batch);

  // Redirection takes place as usual.
  $form_state['redirect'] = 'batch_example/example_2';
}