Adding a Submit Function to a Webform

You are here

Categories:

Most of us use Webform quite a bit to quickly create forms in Drupal.  It comes with a whole lot of features, but what if you need to add an additional step when the form is submitted?

When manually creating a Drupal form we use a "submit function" to process the form and save the results.  Webform doesn't give us direct access to this function, but we can add additional functions.

The solution is to create a module and use hook_form_alter to add the submit function.

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'webform_client_form_123') {
    	$form['#submit'][] = 'MYMODULE_submit';
   }
}

function MYMODULE_submit($form, &$form_state) {
  // Your code goes here
}

You can find the form_id by viewing your HTML.

Tags:

Done right, right here.  

All our work is performed by qualified, experienced developers right here in America.

Talk to Us  Talk to Us

Find out what we can do for your business. Contact us to arrange a demonstration, get a price quote, or just ask questions.

Better still, call us and speak to a Drupal developer right here in Northern Virginia.

(703) 879-6985