1

I have Drupal 7 site. It has custom module named say myproducts. This module has following hook

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

if(isset($form_id) && $form_id=='product_node_form')
{
   $form['#submit'][] = 'myform_form_submit';
}

}


function myform_form_submit(){
 echo 'test submit handler'; exit();
 }

But `myform_form_submit` is not getting called.

Any help highly appreciated.

1 Answer 1

1

The submit for the node form is attached to a specific button, so something like this should work:

$form['actions']['submit']['#submit'][] = 'myform_form_submit';
4
  • do I need to replace #submit with my submit button id ??
    – p21
    Aug 8, 2016 at 19:39
  • Nope, the structure is already there it should just be a matter of adding another function name to that array
    – Clive
    Aug 8, 2016 at 19:40
  • Nopes, still not getting called
    – p21
    Aug 8, 2016 at 19:50
  • Be sure to use dpm($form); within the form_alter hook to find out exactly where the submit element is located within the $form array. It may not necessarily be in $form['actions']. (You need to install the Devel module to run dpm();)
    – argiepiano
    Aug 8, 2016 at 20:29

Your Answer

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

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