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.
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[id]" value="">
<label><span>Post Title</span><input type="text" name="post[title]" value=""></label>
<label><span>Post Text</span><textarea name="post[text]"></textarea></label>
</fieldset>
<input type="submit" name="submit" value="Insert new Post">
</fieldset>
</form>
My questions are
- Can I set disabled to a fieldset using some way?
- 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 ?