I'm trying to add the class 'on-load-click' to any btn with the class 'webform-submit'

<div class="form-actions"><button class="webform-submit button-primary btn btn-primary form-submit" type="submit" name="op" value="Submit">Submit</button>

Currently I have this:

function ntc_bootstrap_hook_form_webform_client_form_alter(&$variables) {
  $element = $variables['element'];
  $label = $element['#value'];
  element_set_attributes($element, array('id', 'name', 'value', 'type'));

  $class_intersection = array_intersect($button_classes, $element['#attributes']['class']);

  if ($variables['element']['#type'] == 'submit' && $variables['element']['#value'] == 'Submit' && $variables['element']['class'] == 'webform-submit') {
    $element['#attributes']['class'][] = 'load-on-click';


However it isn't working and I don't know why. I was following this Add class to Bootstrap login form button to help me, but I can't work it out. Currently there is an error on the button saying "Uncaught Syntax error: unexpected token ';' ", however I'm unsure if it is related. Any help would be greatly appreciated, thanks.

  • If you want to add the class to $element directly you need to assign the variable by reference: $element = &$variables['element']; – 4k4 Jul 15 '20 at 9:45
  • I don't understand what you mean, is that not already on there? – edp Jul 15 '20 at 14:48
  • See php.net/manual/en/… – 4k4 Jul 15 '20 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.