How can I add a custom configuration area to a node edit form just beneath the Authoring Information & Publishing Options section?
Asked
Active
Viewed 2.3k times
2 Answers
14
You can use hook_form_FORM_ID_alter(). Example below:
function my_module_form_node_form_alter(&$form, $form_state) {
// if you are targeting a specific content type then
// you can access the type:
$type = $form['#node']->type;
// Then
if ($type == 'my_content_type') {
// use a contact settings for the sake of this example
$form['contact'] = array(
'#type' => 'fieldset',
'#title' => t('Contact settings'),
'#weight' => 100,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// add simple checkbox to the field set
$form['contact']['approve'] = array(
'#type' =>'checkbox',
'#title' => t('Contact me'),
);
}
}
Now For storing the data I encourage you to see the examples project; it has many code examples with lots of documentation. Also, Check the Form API for more information on different types of form elements. Hope this helps.
-
Thank you so much for your input but I meant something like in my answer below: – sisko Nov 27 '12 at 14:18
-
You answer is identical to the one I provided. – awm Nov 28 '12 at 01:49
-
Very identical but the location of the configuration area is what I was trying to achieve. You code worked without question but I was trying to achieve a different layout – sisko Nov 28 '12 at 09:52
-
1Just a side note to the perfectly working code above: you may avoid conditional nesting by using a guard condition like this: `if ($type != 'my_content_type') { return; }`. Following code now is not nested (intended) which makes your code more readable. – Bernhard Fürst Oct 24 '16 at 09:39
4
The follow code generates the last menu in the attached image:
$form['barclays_epdq'] = array(
'#type' => 'fieldset',
'#access' => TRUE,
'#title' => 'Barclays ePDQ',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#weight' => 100,
'barclays_epdq_active' => array(
'#type' => 'checkbox',
'#title' => 'Enable this webform to send users to your Barclays ePDQ store to make a payment',
'#default_value' => $active_state,
),
);
ps: the form is in hook_form_alter

sisko
- 9,604
- 20
- 67
- 139