Simple as this - I have a Form API fieldset with dynamically changing content. When it's empty, I don't want to show it at all. I use #prefix and #suffix to generate div my AJAX works with.

When I use:

$fieldset['#access'] = FALSE;

it disappears with it's div and no future AJAX call can make it reappear. So, how to hide it with empty, but leave wrapper intact?

1 Answer 1


The easiest way would be to wrap the fieldset itself in another element.

$fieldset_wrapper = array(
  '#prefix' => '<div class="wrapper">',
  '#suffix' => '</div>',

$fieldset_wrapper['fieldset'] = array(
  '#type' => 'fieldset',
  '#access' => FALSE,

As you might expect, setting #access to false will prevent an element from being rendered at all.

  • 1
    Worked. Now I wonder where I have left my head. Anyway, I think this QA might be useful for future visitors, so not going to delete question.
    – Mołot
    Jun 10, 2013 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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