This is in Drupal 7.

I have managed to add a section to the node vertical tab. But I have not found out how to save the value and retrieve the value. After saving the node if i go back to the node edit form it still shows the default value. What am I missing?

function myModule_form_node_form_alter(&$form, &$form_state, $form_id) {
  $form['test_settings'] = array(
    '#type' => 'fieldset', 
    '#title' => t('test settings'), 
    '#weight' => 0, 
    '#collapsible' => TRUE, 
    '#collapsed' => FALSE,
    '#group' => 'additional_settings',

   $form['test_settings']['node_uaid'] = array(
    '#type' => 'textfield',
    '#title' => t('uaid'),
    '#default_value' => variable_get('node_uaid', "default"),
    '#size' => 50,
    '#maxlength' => 50,
    '#description' => t('test UAID.'),
    '#required' => FALSE,
    '#group' => 'settingsform'

The final objective is a field in the node add/edit vertical form that is directly associated with that node. This field should be accessible in relation to the node.

1 Answer 1


Unlike building a settings form in Drupal using system_settings_form(), you need to do more than define the form field so that it's processed. You need to define a submit handler so your custom field can be processed. In your hook_form_alter() add a submit handler:

$form['#submit'][] = 'myModule_form_node_form_submit';

Then define your submit handler to process the form value for saving.

function myModule_form_node_form_submit($form, &$form_state) {
  variable_set('node_uaid', $form_state['values']['node_uaid']);
  • Thank you. I have been looking all over drupal.org for a tutorial on this and there is nothing. Some one should really build a good tutorial on drupal.org for stuff like this. Commented Jun 21, 2016 at 21:41
  • its showing the value but the problem is now its showing that value for every node. How can this value be associated with the node? If i have two nodes one with value-a and the other with value-b Commented Jun 21, 2016 at 21:53
  • You should ask this as a different question (Drupal Answers frowns on back-and-forth commentary of multiple questions). I'll leave one last comment. You need to save a unique variable (e.g. 'node_uaid_'.$nid) to do this. Depending on your needs it might make more sense as a field or DB table entry.
    – Shawn Conn
    Commented Jun 21, 2016 at 22:05
  • Sorry, I thought it was implied that if i'm adding a field to the node add/edit form that i want to associate that field with that node. I can't see any situation where some one would want a field on the add/edit node form that is not associated with the node. The objective is that this field should be associated with the node. I will update my question to better express that this field should be associated with the node. Commented Jun 22, 2016 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.