Main menu

Drupal 7 Form API: Inject a new field into a CCK fieldset

Published by dnovikov on Thu, 04/12/2012 - 15:27

Suppose, you have a node form with some predefined with admin interface fieldsets. If you need to inject a new field into one of these fieldsets, use such code snippet:

function mymodule_form_alter(&$form, $form_state, $form_id) {
$form['brand_new_field'] = array(
'#type' => 'textarea',
'#title' => t('Something'),
$form['#groups']['your_fieldset_name']->children[] = 'brand_new_field';
$form['#fieldgroups']['your_fieldset_name']->children[] = 'brand_new_field';
$form['#group_children']['brand_new_field'] = 'your_fieldset_name';


Thank you. You safe my time

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.