2

I have created a webform, whose id is webform_client_form_1, I have 3 fields:

Name:
Email:
Phone number:

Now I want to extend webform submit function to send SMS to that Phone number. I have a working PHP script which sends SMS, using 3rd party service.

So my question is how to extend the submit function for webform? Is there any hook available or there is other method to do it?

Submit function for webform is: webform_client_form_submit

3

Just append your function to the #submit element to add it to the list of handlers.

MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'webform_client_form_1') {
    $form['#submit'][] = 'webform_client_form_submit';
  }
}
1
  • didn't know we can add multiple submit handler :) thanks for saving my day.
    – shrish
    Sep 16 '15 at 11:10
2

A cleaner solution would be to implement hook_webform_submission_insert. This let's you do it using a native webform hook rather than hacking the form directly.

function MYMODULE_webform_submission_insert($node, $submission) {
  if ($node->nid == 123) {
    // send sms if node id is the one you wanted
  }
}
2
  • I was looking for solution something like this, but seems like this function is called after submission is saved in database. so I guess Shawns solution works better in my case, please enlighten me if I have missed anything here :)
    – shrish
    Sep 16 '15 at 17:23
  • Your question did not specify that you wanted to send the sms before the submission was saved to the db. If that's important just use hook_webform_presave instead.
    – Coleman
    Sep 16 '15 at 19:57

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.