0

webform submit handler not calling in form alter. I have tried solutions like use Drupal\Core\Form\FormStateInterface;

function MODULENAME_form_alter(&$form,$form_state, $form_id) {
  if ($form_id == 'FORMID') {
    $form['actions']['submit']['#submit'][] = 'MODULENAME_form_submit';
  }
}

function MODULENAME_form_submit($form, FormStateInterface $form_state) {
  print_r($form_state);
} 

But this one is not working. Any help?

  • Did you try to add function MODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) ? Also instead of print_r use dsm (you need to enable devel module). – Ismini Jul 11 '17 at 16:03
0

Maybe you can try this :

  function MODULENAME_form_alter(&$form,$form_state, $form_id) {
    if ($form_id == 'FORMID') {
      foreach (array_keys($form['actions']) as $action) {
        if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
          $form['actions'][$action]['#submit'][] = 'MODULENAME_form_submit';
        }
      }
    }
  }

  function MODULENAME_form_submit($form, FormStateInterface $form_state) {
    kint($form_state);
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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