1

I am trying to add classes to my webform. In

hook_webform_element

I can do this

if ($element['#type'] == 'checkboxes') {
  $wrapper_classes = array(
    'form-item',
    'webform-component',
    'large-16 medium-8 small-24 columns',
    'webform-component-' . $type,
  );
}
else {
     $wrapper_classes = array(
    'form-item',
    'webform-component',
    'large-8 medium-8 small-24 columns',
    'webform-component-' . $type,
  );
}

But I do not seem to have access to the submit button. I need to add a couple of classes and also only do it on a certain form so suppose I need the $form_id.

  • did you try hook_form_alter from the Drupal Form API? Let me put this another way. Yes, a webform is made up of webform elements (because years ago they made their own form creation and storage mechanisms separate from Drupal) ... but it's still just a Form and they leverage the Drupal form api still for validation and processing etc. So a custom select widget would be a webform component, the submit button is just a plain HTML input submit. – tenken Jul 25 '14 at 14:44
3

You can do this hook_form_alter(). As all the form element are available in hook_form_alter.

function mymodule_form_alter(&$form, &$form_state, $form_id){
    if ($form_id == 'webform_client_form_YOUR_NODE_ID') {
        $form['actions']['submit']['#attributes']['class'][] = 'newclass';
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.