-1

I am having difficulties regarding the way to add onsubmit to some forms.

I have embedded forms in landings, called via

<?php
    $nid = 12;
    $wnode = node_load($nid);
    $form = drupal_get_form('webform_client_form_' . $nid, $wnode, array());
    print render($form);
?>

I would like these forms to have an extra "onsubmit" attribute to call a function.

I've seen some examples of codes like this

$form['#attributes']['onsubmit'] = 'return myFunction();';

I do not want to put this code in the core of the module, to avoid conflicts with the landings in which the script called is not present.

What would be the right way to get this?

I hope to express myself clearly, thank you

1 Answer 1

0

You need to use hook_form_alter, check the $form_id like if($form_id == MY_FORM_ID) and add your submit handler $form['actions']['submit']['#submit'][] = 'MY_SUBMIT_HANDLER';

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.