3

The following code works.

function bleh_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {
    case "webform_client_form_13":
      $form['#submit'][] = 'bleh_community_submit';
      break;
  }
}

function bleh_community_submit($form, &$form_state) {
  // Do some stuff here.
}

However, is it possible to use code similar to the following one, where the form submit function calls a PHP script (e.g. bleh_community_submit.php) containing the form submission handler?

function bleh_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case "webform_client_form_13":
      $form['#submit'][] = 'bleh_community_submit.php';
      break;
  }
}

// Separate .php file in the module directory with the 
   additional bleh_community_submit function

function bleh_community_submit($form, &$form_state) {
  // Do some stuff here.
}

2 Answers 2

1

Why not do something like

require_once('bleh_community_submit.php');

then call the callback function as per normal?

1

No, there is AFAIK no way to do so. You pretty much have to leave these functions in the .module file (You could place them in a second file which you include always, but that makes no sense performance wise).

Drupal 7 initially had a class and function registry, and it automatically scanned all your files for classes and functions and included them automatically (given that you used drupal_function_exists() for all functions that might be in an include file. But that turned out to be too fragile, too hard to maintain and actually made the site slower when using a opcode cache like APC. So the function part was removed again.

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.