I'm updating a component of mine to use the renderFieldset method and remove some unnecessary code in the form template files. However, some of my fields show / hide based on other preferences in the component. Is there a way to add any kind of show / hide logic when using the renderFieldset method? Or would I have to manually parse the form and output the logic inline as I'm doing currently?

1 Answer 1


You can use the Form API setFieldAttribute() method to set the attribute of a field based on your config params. Then when you do renderFieldset() - which basically just does a renderField() for each of the fields in the fieldset - the revised field attribute will be taken into account when that field is rendered.

So what you probably want to do is something like

$form = getForm(...);
if ("myfield1" should be hidden)
    $form->setFieldAttribute("myfield1", "type", "hidden");

where "myfield1" is the name of the field you want to hide. Then do, as normal:


Your Answer

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

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