0

Why is my submit function never been executed?

/**
 * Implements hook_menu().
 */
function simpleexample_menu() {

  $items['simple-example-page'] = array(
    'title' => 'Simple Multi-Step Form',
    'page callback' => 'create_request_custom',
    'access callback' => TRUE,
  );

  return $items;
}

function create_request_custom() {
  module_load_include('inc', 'node', 'node.pages');
  $form = node_add('request');

  $form['simpleexample'] = array(
    '#type' => 'value',
    '#value' => simpleexample_get_session(),
  );
  $form['actions']['submit']['#submit'][] = 'create_request_custom_submit';

  return $form;
}

function create_request_custom_submit($form, &$form_state) {
  // never executing that
  $params = array(
    'nid' => $form_state['values']['nid'],
    'session_id' => $form_state['values']['simpleexample'],
  );
  .....

}

1 Answer 1

2

Forms need to be called via drupal_get_form() that processes your $form array into a form. Including the submit handling. So it should look like more like this:

/**
 * Implements hook_menu().
 */
function simpleexample_menu() {

  $items['simple-example-page'] = array(
    'title' => 'Simple Multi-Step Form',
    'page callback' => 'drupal_get_form', // Tell drupal to use the drupal_get_form function.
    'page arguments' => array('create_request_custom'), // Pass the form function as argument for the page callback.
    'access callback' => TRUE,
  );

Also you'll probably want to add the $form and &$form_state variables to the form function.

function create_request_custom($form, &$form_state) {
  // Your form function 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.