specify $form elements to be excluded from display? I want to hide certain elements in form using form_alter or a template file. I have read somewhere that in Drupal 7 , we can specify $form elements so it will not display in form, but I can't remember!
Not unset() but some other function!
Using unset() isn't a good solution for forms (as I think you know), as you never know what submit/validate handlers might be expecting the unset element to exist when they're processed. This can lead to unwanted errors.

There are three methods you can safely use to 'hide' a form element


Use '#type' =&gt; 'value' on the element, which will have the effect that the value for the element will still be passed through to the submit/validate functions with its #value as normal. This is my preferred method.
Use '#access' =&gt; FALSE on the element to denote it should not be outputted to the screen.
Use '#type' =&gt; 'hidden' as Bart has suggested (although use of this depends on your use case; I imagine if you're trying to hide the value of a form element you don't want to output it in the form as a hidden input).