http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...

hidden

Description: Store data in a hidden form field.

Properties: #prefix, #suffix, #type, #value

#default_value is also a property. If you want to allow javascript to modify a hidden field's value, then you have to use #default_value to set the starting value when drawing the form. If you use #value, then javascript changes to the value will not be available in the form's _submit() function.

Comments

webchick’s picture

It's my understanding that giving a field type like hidden or value a #default_value is Very Very Dangerous (tm). I'll check with chx or eaton, but afaik this is a practice greatly discouraged. I'm not sure what the workaround is, however.

nielsbom’s picture

Component: Developer Guide » Correction/Clarification

Changed the component to reflect the new component categorization. See http://drupal.org/node/301443
-nielsbom

add1sun’s picture

Project: Documentation » Drupal core
Version: » 5.x-dev
Component: Correction/Clarification » documentation

moving to drupal queue for API docs.

jhodgdon’s picture

Version: 5.x-dev » 7.x-dev

Looking at the Drupal 7 source, I see both #value and #default_value being used.

From form_process_hidden_tabs():

  $element[$name . '__active_tab'] = array(
    '#type' => 'hidden',
    '#default_value' => $element['#default_tab'],
    '#attributes' => array('class' => 'vertical-tabs-active-tab'),
  );

From form_prepare_form():

    $form['form_id'] = array(
      '#type' => 'hidden',
      '#value' => $form_id,
      '#id' => form_clean_id("edit-$form_id"),
    );

It looks like the former example is for use with JavaScript, and the latter is a static value, so probably this reporter is correct.

I will update the form API docs accordingly.

jhodgdon’s picture

Status: Active » Fixed

I've fixed this in both the D6 and D7 versions of http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/7

Changes checked into the contrib repository; should be live sometime in the next day or two on api.drupal.org.

jhodgdon’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.