Drupal Answers Asked by user7355700 on December 14, 2021
I’m trying to add a field that would be displayed after the submit button in the rendered HTML in my hook_form_alter.
e.g.
$form['include_card'] = [
'#type' => 'checkbox',
'#title' => t('Include gift card'),
'#weight' => 25,
];
Weight doesn’t seem to have any bearing on it. How would you set that up?
The submit button will likely be inside an Actions element, which has a default weight of 100.
You could add your field to the actions element:
$form['actions']['include_card'] = ...
At which point the weight of include_card
will be relative to the buttons/etc that are inside the actions element (and 25 will probably work).
Another option would be to position your element directly after the actions:
$form['include_card'] = [
'#type' => 'checkbox',
'#title' => t('Include gift card'),
'#weight' => $form['actions']['#weight'] + 1,
];
Answered by Clive on December 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP