Form API-passing on the NID in a hidden field? So, here's my issue. I have a university course page. I want to display a list of students currently weight listed for the course, and give the option for the student to add their name to the weight list. 

I've outputted the current student weight list through a custom template file just fine. I've also made a one button form through a custom module that simply calls a submit function. Then I call that form on my node template. That part works all fine. 

Then, all I need for this form to work is the current User's UID (which can be called easily from my form submit function in my module). And the NID that their name should be attached to. Where I'm having difficulty is the NID part. I can't figure out how I can add that to my custom form built through my module with Form API. 

Right now, I'm setting a variable and calling that variable in the submit function.The problem there is it will screw up the system if more than one student is looking at different pages and submits it. So there needs to be way that I can set the current NID that the form sits on, then call it through my submit handler. 

I've been searching google up and down for this, and I can't figure out how to set a hidden field with the current NID the form is on. 

Any help would be greatly appreciated. 

Edit: Here is my code currently for reference: 

function wl_add_form($form_state) {


 $form['submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Add Name to List'),
  '#submit' =&gt; array('wl_add_form_submit_function'),
);

  return $form;
}


//Add me to weight list functions 
function wl_add_form_submit_function($form, &amp;$form_state) {

//dpm($form);
  //Handle the student add
  global $user;
  //get the User ID
  $userID = $user-&gt;uid;
  //get the NID from the node variable we set in the node-course template: 

  $nid= variable_get($wlNID); 
  $node = node_load($nid);
  $count = count($node-&gt;field_course_weight_student);
  $node-&gt;field_course_weight_student[$count]['uid'] = $userID; // another user
  node_save($node);
  drupal_set_message(t('Your name has been added to the weight list'));



}
Just save the node ID in $_SESSION. 

Using variable_set() has another effect, apart saving a value that is valid for all the users: It clears the cache Drupal uses for the Drupal variables, with the effect they are reloaded from the database the next time Drupal bootstraps. Compare the code used by variable_set() and variable_initialize(). (Similar code is executed by Drupal 6.)

  db_merge('variable')-&gt;key(array('name' =&gt; $name))-&gt;fields(array('value' =&gt; serialize($value)))-&gt;execute();

  cache_clear_all('variables', 'cache_bootstrap');

  $conf[$name] = $value;




  // NOTE: caching the variables improves performance by 20% when serving
  // cached pages.
  if ($cached = cache_get('variables', 'cache_bootstrap')) {
    $variables = $cached-&gt;data;
  }
  else {
    // Cache miss. Avoid a stampede.
    $name = 'variable_init';
    if (!lock_acquire($name, 1)) {
      // Another request is building the variable cache.
      // Wait, then re-run this function.
      lock_wait($name);
      return variable_initialize($conf);
    }
    else {
      // Proceed with variable rebuild.
      $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')-&gt;fetchAllKeyed());
      cache_set('variables', $variables, 'cache_bootstrap');
      lock_release($name);
    }
  }

  foreach ($conf as $name =&gt; $value) {
    $variables[$name] = $value;
  }


As for an example of how to use $_SESSION in a form, see node_filter_form(), the form builder function that handles the form that allows to filter nodes in admin/content/node. 



  $session = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();
  $filters = node_filters();

  $i = 0;
  $form['filters'] = array(
    '#type' =&gt; 'fieldset',
    '#title' =&gt; t('Show only items where'),
    '#theme' =&gt; 'exposed_filters__node',
  );
  foreach ($session as $filter) {
    list($type, $value) = $filter;
    if ($type == 'term') {
      // Load term name from DB rather than search and parse options array.
      $value = module_invoke('taxonomy', 'term_load', $value);
      $value = $value-&gt;name;
    }
    elseif ($type == 'language') {
      $value = $value == LANGUAGE_NONE ? t('Language neutral') : module_invoke('locale', 'language_name', $value);
    }
    else {
      $value = $filters[$type]['options'][$value];
    }
    $t_args = array(
      '%property' =&gt; $filters[$type]['title'],
      '%value' =&gt; $value,
    );
    if ($i++) {
      $form['filters']['current'][] = array('#markup' =&gt; t('and where %property is %value', $t_args));
    }
    else {
      $form['filters']['current'][] = array('#markup' =&gt; t('where %property is %value', $t_args));
    }
    if (in_array($type, array('type', 'language'))) {
      // Remove the option if it is already being filtered on.
      unset($filters[$type]);
    }
  }

  $form['filters']['status'] = array(
    '#type' =&gt; 'container',
    '#attributes' =&gt; array('class' =&gt; array('clearfix')),
    '#prefix' =&gt; ($i ? '&lt;div class="additional-filters"&gt;' . t('and where') . '&lt;/div&gt;' : ''),
  );
  $form['filters']['status']['filters'] = array(
    '#type' =&gt; 'container',
    '#attributes' =&gt; array('class' =&gt; array('filters')),
  );
  foreach ($filters as $key =&gt; $filter) {
    $form['filters']['status']['filters'][$key] = array(
      '#type' =&gt; 'select',
      '#options' =&gt; $filter['options'],
      '#title' =&gt; $filter['title'],
      '#default_value' =&gt; '[any]',
    );
  }


Its form submission handler sets $_SESSION with the values entered by the user.

  // Apply every filter that has a choice selected other than 'any'.
  foreach ($filters as $filter =&gt; $options) {
    if (isset($form_state['values'][$filter]) &amp;&amp; $form_state['values'][$filter] != '[any]') {
      // Flatten the options array to accommodate hierarchical/nested options.
      $flat_options = form_options_flatten($filters[$filter]['options']);
      // Only accept valid selections offered on the dropdown, block bad input.
      if (isset($flat_options[$form_state['values'][$filter]])) {
        $_SESSION['node_overview_filter'][] = array($filter, $form_state['values'][$filter]);
      }
    }
  }