Moving a field into a (different) group/fieldset using hook_form_alter()
The following demonstrates how to move a field into a different fieldset within a form using hook_form_alter() and a special #after_build form property.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
function mymodule_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'status_node_form' && $form['nid']['#value']) { $form['send_notification'] = array( '#type' => 'submit', '#value' => t('Send Notification'), '#submit' => array('mymodule_notify_submit'), ); $form['#after_build'][] = 'mymodule_notification_afterbuild'; } } function mymodule_notification_afterbuild($form, $form_state) { // Add the notifications button to the "Notifications" field group // (defined in the content type field manager) $form['group_notifications']['send_notification'] = $form['send_notification']; unset($form['send_notification']); return $form; } |