I am trying to remove a fieldset from a form. I have not found a function that does this, so I do it through an array to remove them individually.

$infofield = $form->getFieldset('company');

foreach ($infofield as $key => $field) {
       $name = preg_split("/[\[\]]/", $field->name);

I am using this method but I do not like.

How can I recover from the $infofield only the name of the field without the jform or alternatively there is a method to romeve the fieldset ?

  • Why do you want to remove the fieldset element? Aug 8 '17 at 12:24

I see a lot of weird answers with regular expressions and attribute handling... Why? Joomla! has a great API in JForm to do everything you need. Since it's not quite clear what you want to accomplish I'll give you three alternatives for doing things the Joomla! Way.

If you want to remove a specific field from a form it's easy to do it if you know the name of the fieldset and the field.

$form->removeField('my_field_name', 'my_fieldset_name');

If you want to get the names of all fields in a fieldset -- and possibly remove them from the form -- try:

$fields = $form->getFieldset('my_fieldset_name');
foreach ($fields as $field)
    $name = $field->getAttribute('name');
    // And possibly delete the field here:
    // $form->removeField($name, 'my_fieldset_name');

However, this removes the fields, not the fieldset. If you want to remove an entire fieldset you just need to know that before Joomla! 1.6 they were called "groups", hence the surviving method being called removeGroup:


I recommend using an IDE such as PhpStorm or NetBeans and type hinting (in the form of /** @var JForm $form */)to get autocompletion of the method names. In most IDEs you can CTRL-click (macOS: CMD-click) the method name to go into its declaration in Joomla's core to understand what it does. That's how I learned how Joomla works: following the code in an IDE. It's not magic, it's Open Source Software :)


I could be wrong and haven't tested this, but try using:

<?php foreach ($this->form->getFieldset('company') as $field): ?>
    $name = preg_split("/[\[\]]/", $field->name);

If you don't care about the value inside the company field and you just want to hide it in the form, then why not just use CSS? Set the display attribute of its div to none and that's it.


Use getAttribute() to get an attribute of the field as it appears in XML form:

foreach ($form->getFieldset('company') as $field)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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