I'm using Drupal 7

I'm creating a node through a node add form. The settings are such that it should by default be published. I'm trying to hide some of the options from the user, but when I


for some reason the node does is no longer published by default. I've tried tracing out the value of that portion of the form

drupal_set_message('Options'.'<pre>'.   print_r($form['options'], TRUE) .'</pre>');

and I get the same values when the field is visible as when it is hidden. Seems like perhaps something is fishy?

2 Answers 2


When you hide the form['options'] array you essentially set it to 0. Which means the published field will always be 0 (unpublished). Try hiding the fields with CSS or JS if you need it to be conditional.

  • is this true of any form? or just the options portion of the form. did unset do this as well, I know that was the way to do it in drupal 6
    – user379468
    Dec 29, 2011 at 22:05

I was able to hide it and still get it to work correctly. I had to dig into the options object and set a number of parameters to true. Not sure if I needed to do this to them all, but here is the code.

    $form['options']['status']['#default_value'] = TRUE;
    $form['options']['status']['#input'] = TRUE;
    $form['options']['status']['#return_value'] = TRUE;
    $form['options']['status']['#value'] = TRUE;
    $form['options']['status']['#checked'] = TRUE;

This is inside the hook_form_alter() function in a custom module

  • Actually, also found that if you set the type of the field to hidden, it still works, but does not display, you can do it like this $form['field_name']['und'][0]['nid']['#type'] = 'hidden';
    – user379468
    Jan 2, 2012 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.