1

On a Drupal 7 Webform I've added a button using a markup field like this:

<button name="get" value="" type="submit" class="primary-submit submit" id="get">
Get Address
</button>

I am directing it to a submit handler like this:

function new_webform_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'webform_client_form_88') {
    $form['submitted']['name']['get']['#submit'][]='new_webform_get_submit';
    dpm($form);
  }
}

I can tell the button #submit is being changed, but the whole form is submitted instead of executing the handler code. What am I doing wrong?

  • I think you forgot your code snippets =\ – Chapabu Apr 6 '12 at 15:30
1

Turns out the form was not actually being submitted but the custom handler was not being processed because the form validation was failing. I disabled it with

$form['submitted']['name']['get']['#limit_validation_errors']=array();

and now the handler works.

1

In a general scenario, to add a custom submit handler to any Drupal form you can implement hook_form_alter or hook_form_form_id_alter

you will have to add the submit handler in the #submit array, something like this,

$form['#submit'][] = 'my_custom_submit_handler'; //this function will accept $form and $form_state as args.

same can be done for #validate if you want a extra validate handler.

Cheers.

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.