Example code to add extra submit handler to batch update form

Created on 23 February 2010, almost 15 years ago
Updated 3 September 2024, 4 months ago

I needed to add a second submit handler to the batch update form.

I see in the batch form definition, you can define

'#submit' => 'custom_submit_handler',

However, that handler is only called if the domain_action is set to 'custom'

I needed to use both domain_conf as the handler add a separate submit handler to do additional processing.

I ended up using the form_alter snippet below:

<?php
/**
 * Implementation of hook_form_FORMID_alter
 */
function example_module_form_domain_batch_form_alter($form, &$form_state) {
  // if custom handler set, let it handle the submit.
  if( $form['handler']['#value'] == 'custom' ){
    return;
  }elseif( isset($form['submit_handler']) && function_exists($form['submit_handler']['#value']) ){
    // add second submit handler, if present
    $form['#submit'][] = $form['submit_handler']['#value'];
  }
}
?>

That way domain_conf ( or the configured handler ) can handle saving the settings and then pass control onto another custom submit handler. If the handler is already set to custom, the domain module will add the submit_handler itself.

hth,

DT

Feature request
Status

Closed: outdated

Version

3.0

Component

Code

Created by

🇳🇿New Zealand davidwhthomas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    I'll close this issue due to inactivity for 12 years and upcoming EOL of Drupal 7 in January 2025 . While the project's version for Drupal 7 will surely keep providing support for security issues and website breaking bug fixes for Drupal 7, we should try to minimize the open issues for Drupal 7 in the queue as much as possible. A big thanks around for the report and all the efforts in here. Feel free to re-open if you can provide a fix or found an additional related problem which increases the issue priority.

Production build 0.71.5 2024