On a Drupal site, when a form submission is done. I need to trigger a SMS. I am unable to edit the form submit code. Please let me know how to add a function to webform submit button. So that on SUBMIT button click the SMS function get executed as well the form data goes to the database.
1 Answer
Your mileage will vary, but it's the same as adding submit handlers to any form:
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'foo') {
$form['actions']['submit']['#submit'][] = 'MYMODULE_some_function';
}
}
function MYMODULE_some_function($form, &$form_state) {
// Do something...
}
See hook_form_alter()
for full details.
-
But the problem with MYMODULE_form_alter function is the submissions will not get stored in the database.– user7048Commented Feb 11, 2014 at 16:19
-
Sorry I don't understand - you're adding an extra submit handler, you're not replacing the existing one(s). Is that what you meant?– Clive ♦Commented Feb 11, 2014 at 16:20
-
yes exactly.. on submit click i want both functions. Default form submit action as well as additional functionality of sending a SMS– user7048Commented Feb 11, 2014 at 16:23
-
Yep, that's exactly what the above code does. Always best to check whether something works first before guessing that it won't– Clive ♦Commented Feb 11, 2014 at 16:23
-
1That would probably refer to the JS
alter()
function (PHP doesn't have a namesake). Good luck getting it sorted anyway– Clive ♦Commented Feb 11, 2014 at 16:31