I am working on a custom module that hooks into Webform in various ways. Right now I am saving variables using system_settings_form and understand that these will go into a Drupal variables table somewhere.

What I am trying to do is pass the NID of the Webform that my form appears on into the variable name, so I can pull them out based on that particular form in the future.

For instance:

function MYMODULENAME_form($form, &$form_state) {
  $form['MYMODULENAME_group_node_' . $nid] = array(
    '#type' => 'textfield',                                                                                                                         
    '#title' => t('Group ID'),                                                                                                                      
    '#default_value' => variable_get('MYMODULENAME_group_node_' . $nid),                                                                                                   
    '#size' => 6,                                                                                                                                   
    '#maxlength' => 6,                                                                                                                              
    '#description' => t('6 Digit Segment ID Identifier'),                                                                                             
    '#required' => TRUE,                                                                                                                            
 return system_settings_form($form);

Where $nid is the Node ID from the form.

I am not sure if this is best practice at all. If anyone could point me in the right direction that would be most appreciated.

  • 1
    Standard practice would be to add a new field to the webform content type, and store the data for each applicable webform in there. The variables table isn't really meant to store data for individual pieces of content, it's for more general variables (the site name and email for example, or the settings for a particular content type). Using a field also has the advantage of automatic integration with the node display/views/rules/etc – Clive Aug 29 '13 at 17:19
  • That sounds like a plan. Thanks for the quick feedback. – mikeyrocks Aug 29 '13 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.