I know how to populate the form fields in hook_form_alter but i have no idea how to hide them...

regards Volkan


muschpusch’s picture

I found a solution at lullabot


Too lazy to read try to add '#access' = false to your form element

$form['author']['name']['#access'] = FALSE;

westbywest’s picture

Please note that if you restrict the access permissions for a form field, then you are also restricting the active user's ability to submit any value for that field, whether via manual entry or via hook_form_alter() 'fu.

That is, this hook_form_alter() code wouldn't work:

$form['author']['name']['#access'] = FALSE;
$form['author']['name']['#value'] = 'something';

As an alternative, try simply hiding the field (or change to type hidden) if you still want the acting user to modify a form's field in some controlled way:

$form['author']['name']['#prefix'] = '<div style="display:none;">';
$form['author']['name']['#value'] = 'something';
$form['author']['name']['#suffix'] = '</div>';
cdmo’s picture

Changing type to hidden also prevents setting values via hook_form_alter() calls. Guess we're left with hiding via CSS.


ehsankhfr’s picture

I checked both unset($form[...]) and $form['...']['#access']=false , both didn't work.

I guess styling hidden is the only option remained for this issue.