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?

up vote 1 down vote accepted

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 '13 at 10:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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