How can I disable fieldset?

Hi.

I want to disable a part of a form, so try to use fieldset.

I made a fieldset

class ShinseiAppFieldSet extends Fieldset
{
    public function init()
    {
        $this->add([
            'type' => 'hidden',
            'name' => 'id',
        ]);

        $this->add([
            'type' => 'text',
            'name' => 'title',
            'options' => [
                'label' => 'Post Title',
            ],
        ]);

        $this->add([
            'type' => 'textarea',
            'name' => 'text',
            'options' => [
                'label' => 'Post Text',
            ],
        ]);
    }
}

And add it in a form

class ShinseiForm extends Form
{
    public function init()
    {
        $this->add([
            'name' => 'post',
            'type' => ShinseiAppFieldSet::class,
        ]);

        $this->add([
            'type' => 'submit',
            'name' => 'submit',
            'attributes' => [
                'value' => 'Insert new Post',
            ],
        ]);
    }
}

Then I set the attribute ‘disabled’ to fieldset, and render it in a view.

<?php
$this->form->prepare();
$form = $this->form;
$fields = $form->get("post");
$fields->setAttribute("disabled","true");

echo $this->form()->openTag($form); <---BREKPOINT
echo $this->formCollection($form);
echo $this->form()->closeTag();-----------------
In debugger, it seems that the field set has attribute ‘disabled’=’true’.
?>

At the break point, it seems that fieldset ‘post’ has the attribute disabled.
スクリーンショット 2021-11-04 085025

But it seems that there is no effect in rendered HTML.

<form method="POST">
<fieldset >
    <fieldset name="post">  <--------No effect
        <input type="hidden" name="post&#x5B;id&#x5D;" value="">
        <label><span>Post Title</span><input type="text" name="post&#x5B;title&#x5D;" value=""></label>
        <label><span>Post Text</span><textarea name="post&#x5B;text&#x5D;"></textarea></label>
    </fieldset>
    <input type="submit" name="submit" value="Insert&#x20;new&#x20;Post">
</fieldset>
</form>

My questions are

  1. Can I set disabled to a fieldset using some way?
  2. It seem that the fieldset has no method like openTag. Is there any way to use fieldset like
<fieldset name=’post’ disabled=true>
	<?= $form->formRow($this->get(“foo”)) ?>
</fieldset>

Is there any idea ?

I think the disabled attribute is missing in the configuration for valid attributes:

And also the attribute form:

Please create an issue report. Thanks in advance! :+1:t3:


The entire code can be reduced to:

/**
 * @var Laminas\View\Renderer\PhpRenderer|Laminas\Form\View\HelperTrait $this
 * @var Laminas\Form\Form $form
 */

$form->get('post')->setAttribute('disabled', true);

echo $this->form($form);

Thank you for your comment (especially for shorthand).
I’m going to create the report.

1 Like