2

I have a cck field with the name of field_testfield And I have displayed it in the form in .module file like the follwoing.
$form['field_testfield']['#weight'] = 10;
Now I want to enclose it in a fieldset. Any idea about this?

Ahmad
  • 2,099
  • 10
  • 42
  • 79
  • I have done it by creating group in the manage fields of the content type. but now the problem is how to handle its weight because it appear at the top of the form and I want to display it in proper position in the form? – Ahmad May 20 '11 at 09:50

1 Answers1

1

the correct way to implement fieldsets is

$form['my_fieldset'] = array(
  '#type' => 'fieldset',
  '#weight' => 0,
  '#collapsible' => TRUE, //is the fieldset collabsible?
  '#collapsed' => TRUE //is the fieldset collabsped at start?
);

to add fields inside this fieldset you would append the elements to the fieldset array

$form['my_fieldset']['custom_field_1'] = array(
  '#type' => 'textarea', //or whatever
  '#weight' => 0 //the weight set here is the weight of the element inside the fieldset
);
tobbr
  • 2,046
  • 3
  • 14
  • 15
  • This is fine but it is for the form fields in .module file. And I have a CCK field which i created in a content type manage fields. How would add that field inside the fieldset? I did it by creating a group in the manage fields of the content type. – Ahmad May 27 '11 at 04:44