How do I create a hidden field programatically? I've got a module that is creating fields programatically, all working so far. The code is below. This may be useful as-is if you are trying to create checkboxe fields from an array of values:

    /**
     * Helper function to create fields for workflow approvers
     *
     */

    function _create_approval_fields($approverRolesClean){
      $fieldPrefix = 'wf_';

      // TODO: If an existing field is removed, delete it.

      foreach ($approverRolesClean as $approverRole) {
        $cleanRole = preg_replace('/[^a-z]/', "", strtolower($approverRole));
        $fieldName = $fieldPrefix.$cleanRole;
        if (!field_info_field($fieldName)) {
          $field = array(
            'field_name' =&gt; $fieldName, 
            'type' =&gt; 'list_boolean',
            'widget' =&gt; array(
              'type' =&gt; 'options_onoff',
              'settings' =&gt; array(
                'display_label' =&gt; '1',
              ),
            ),
            'settings' =&gt; array(
              'allowed_values' =&gt; array(
                '0' =&gt; 'No',
                '1' =&gt; 'Yes',
                ),
              ),
            );
          field_create_field($field);
        }
        //Hardcoded:
        if (!field_info_instance('node', $fieldName, 'contenttype')) {
          $instance = array(
            'field_name' =&gt; $fieldName, 
            'entity_type' =&gt; 'node', 
            'label' =&gt; 'Approved by ' . $approverRole, 
            //Hardcoded:
            'bundle' =&gt; 'contenttype',
            'widget' =&gt; array(
              'type' =&gt; 'options_onoff',
              'settings' =&gt; array(
                'display_label' =&gt; '1',
              ),
            ),
          );
          field_create_instance($instance);
        }
      }
    }


I set the value of the fields outside the Edit screen - so they never need to show there. I'm sure there is a settings parameter that I can add to hide it, but not sure where to find the doc. I don't think no_ui is what I need.

Otherwise I can use the form api to hide it at render time, but that doesn't seem as elegant.

Thanks,

Jack
I don't follow the example 100%, but to answer the question - in D7 you can set '#type' =&gt; 'hidden', '#value' =&gt; 'foo' or just do '#my_custom_key' =&gt; 'my custom value' and it will be available to you in the submit handler (or elsewhere, such as hook_field_attach_submit()).