문제

I need to theme the login form. I need additional css classes and tabindex for the form elements.

Now I have a problem with these both for the login button.

In template.php I use 'attributes' for that. For e.g. the password field it works perfect with this code:

$form['pass']['#attributes']['class'][] = 'input-sm form-control';
$form['pass']['#attributes']['tabindex'][] = '2';

When I use this for the button - nothing is rendered in html:

$form['op']['#attributes']['class'][] = 'test-button';
$form['op']['#attributes']['tabindex'][] = '3';

'op' is the name of the login button which I can see in html output.

How can I get the 'class' and 'tabindex' to the login button?

도움이 되었습니까?

해결책

For the button you should use $form['#submit'].

In any case you can use hook_form_alter() and devel's dpm($form) to get the form data. A generic example:

function MYTHEME_form_alter(&$form, &$form_state, $form_id) {
  dpm($form);
}

The submit button may be accessed like this for a common Drupal theme (structure taken from the dpm() function):

$form['actions']['submit']['#attributes']['tabindex'][] = "2";

One important thing here is to be careful because you may override the form again later on your theme... In this case look for the very last hook and apply changes there.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top