8.3.x common.inc hide(&$element)
8.0.x common.inc hide(&$element)
8.1.x common.inc hide(&$element)
8.2.x common.inc hide(&$element)
8.4.x common.inc hide(&$element)
7.x common.inc hide(&$element)

Hides an element from later rendering.

The first time render() or drupal_render() is called on an element tree, as each element in the tree is rendered, it is marked with a #printed flag and the rendered children of the element are cached. Subsequent calls to render() or drupal_render() will not traverse the child tree of this element again: they will just use the cached children. So if you want to hide an element, be sure to call hide() on the element before its parent tree is rendered for the first time, as it will have no effect on subsequent renderings of the parent tree.


$element: The element to be hidden.

Return value

The element.

See also



7 calls to hide()
comment.tpl.php in modules/comment/comment.tpl.php
Default theme implementation for comments.
comment.tpl.php in themes/garland/comment.tpl.php
comment.tpl.php in themes/bartik/templates/comment.tpl.php
Bartik's theme implementation for comments.
node.tpl.php in modules/node/node.tpl.php
Default theme implementation to display a node.
node.tpl.php in themes/garland/node.tpl.php

... See full list

3 string references to 'hide'
theme_user_permission_description in modules/user/user.admin.inc
Returns HTML for an individual permission description.
user_admin_permissions in modules/user/user.admin.inc
Menu callback: administer permissions.
user_theme in modules/user/user.module
Implements hook_theme().


includes/common.inc, line 6183
Common functions that many Drupal modules will need to reference.


function hide(&$element) {
  $element['#printed'] = TRUE;
  return $element;


Elijah Lynn’s picture

This is great, I was setting certain form elements to ...['#access'] = FALSE; prior. This is much better!

roynilanjan’s picture

#access=FALSE is always a better option, as it never been render at-all

stickywes’s picture

Due to the fact that hide() and show() simply toggle the #printed attribute on an element, the Form API will not reject input that has been submitted for these form elements (it has no way to know).

This means that through Javascript or other means, one can still submit data to a hidden form element. Form elements that have been #disabled or #access = FALSE are protected from this vulnerability.

arne_hortell’s picture

This implementation is incorrect
function hide(&$element) {
$element['#printed'] = TRUE;
return $element;
Because, if hide is called on an element thats not defined before, it will be defined.
Further down in code will imagine that the element is created but its not.
Better implementation should be
function hide(&$element) {
if (!empty($element))
$element['#printed'] = TRUE;
return $element;

okey-on’s picture

True! A better implementation

rooby’s picture

This is just documentation.

If you think that code should be changed you should open an issue in the issue queue. The Drupal core issue queue is at https://www.drupal.org/project/issues/drupal

davewilly’s picture

Using hide() on field of type Date will give you a validation error, so #access = FALSE has to be used.

jlarrubia’s picture

The property #access=FALSE doesn't work properly to hide fields in the form "field_ui_table" (Manage display form in a content type). It hides the field setup but still displays the container markup. The function hide() removes any trace.