How to hide and/or prevent access to fields in a form,  such as group_audience for organic groups This has been troubleing me for a while.. When i try to hide fields like the group audience field, or the publishing setting from a form, on validation the form set both of these field to a null value, even though the defaut value as been correctly declared. 

I tried to use Invisible, #access, unset hidden nothing work! This is very troubleing because for my current project users can edit only small bits of their profile at the time, for instance just the address or the picture, so if i hide group audience the user ends up kicked out of the groups he belongs at every edit. 

I ended up using the code below to hide these field while still keeping the user in their group.

$variables['user_edit_about']['group_audience']= $temp['group_audience'];       
$variables['user_edit_about']['group_audience']['#prefix'] = '&lt;div style="display:none;"&gt;';
$variables['user_edit_about']['group_audience']['#suffix'] = '&lt;/div&gt;';


Would anyone think of a better way to achieve this ?  

Thanks
Edit:

Ok I figured it out.  Put this in your custom module:

function example_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    if($form_id == 'story_node_form') {
        $form['title']['#value'] = 'hot stuff';
        $form['title']['#access'] = FALSE;

    }
}


This will set the title of the story node to 'hot stuff' and it will NOT be render on the page because #access = FALSE;

You can add more granularity control inside hook_form_alter()
like 

  global $user;

  // Check to see if $user has does not have the administrator role.
  if (!in_array('administrator', array_values($user-&gt;roles))) {
    $form['title']['#access'] = FALSE;
  }


This works for Drupal 6 &amp; 7.

Old Answer (ignore):

Its been awhile since I did something like this,  so I may have it wrong.
If you set the  [#value] of a form item,  it will not be visible on the form.

I did this in Drupal 6,  hook_form_alter() in a custom module.  I don't know if it will work in Drupal 7 and I don't know if you can do it in a preprocess function