Double click prevention on form submission ignoring callback in forms with multiple submit buttons

Created on 24 July 2023, over 1 year ago
Updated 5 August 2023, over 1 year ago

Problem/Motivation

When a form has multiple submit buttons, each one with a different callback sometimes the wrong callback actions is called

Steps to reproduce

Create a custom form with multiple callbacks and when it submits ignore the callback value and submit always to the first one, callback_a

<?php
$form['submit_calback_a']['1'] = array(
      '#type' => 'submit',
      '#submit' => array(
        'calback_a',
      ),
      '#value' => 'lorem',
      '#attributes' => array(
        'class' => array('btn-link'),
        'title' => t('calback_a'),
    
      ),
      '#name' => 'submit-callback_a',
    );

 $form['submit_calback_b']['1'] = array(
      '#type' => 'submit',
      '#submit' => array(
        'calback_b',
      ),
      '#value' => 'lorem',
      '#attributes' => array(
        'class' => array('btn-link'),
        'title' => t('calback_b'),
    
      ),
      '#name' => 'submit-callback_b',
    );

   $form['submit_calback_c']['1'] = array(
      '#type' => 'submit',
      '#submit' => array(
        'calback_c',
      ),
      '#value' => 'lorem',
      '#attributes' => array(
        'class' => array('btn-link'),
        'title' => t('calback_c'),
    
      ),
      '#name' => 'submit-callback_c',
    );
?>
πŸ› Bug report
Status

Active

Version

7.0 ⚰️

Component
JavascriptΒ  β†’

Last updated about 2 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom pjflopes

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.

  • First commit to issue fork.
  • According to me. you can do like this as well.

    <?php
    function mymodule_custom_form($form, &$form_state) {
    $form['submit_calback_a']['1'] = array(
          '#type' => 'submit',
          '#value' => 'calback_a',
          '#attributes' => array(
            'class' => array('btn-link'),
            'title' => t('calback_a'),
          ),
        );
    
     $form['submit_calback_b']['1'] = array(
          '#type' => 'submit',
          '#value' => 'calback_b',
          '#attributes' => array(
            'class' => array('btn-link'),
            'title' => t('calback_b'),
          ),
        );
    
       $form['submit_calback_c']['1'] = array(
          '#type' => 'submit',
          '#value' => 'calback_c',
          '#attributes' => array(
            'class' => array('btn-link'),
            'title' => t('calback_c'),
          ),
        );
    }
    
    function mymodule_custom_form_submit($form, &$form_state) {
      $values = $form_state['values'];
      if ($values['op'] == t('calback_a')) {
          calback_a();
      }
      if ($values['op'] == t('calback_b')) {
          calback_b();
      }
      if ($values['op'] == t('calback_c')) {
          calback_c();
      }
    }
    
  • πŸ‡ΈπŸ‡°Slovakia poker10

    Thanks for reporting this @jlopes23.

    I have tested this manually on clean Drupal 7.98 install with a simple form (code you provided) and it seems like the correct submit handlers are called. Can you please test this with a simple custom form containing only the code you provided, if it is still a problem?

Production build 0.71.5 2024