Recently I was trying to create a hidden field on a form I’ve been working with and couldn’t find anything in the Drupal documentation that explained how to create a hidden form. The solution is actually quite simple.
In this case I was using the hidden field to store a primary key value.
$form[‘form_group’][‘form_name’] = array(
‘#title’ => t(‘ID’),
‘#value’ => $value,
‘#type’ => ‘hidden,
);
It’s as simple as setting the type to hidden.