diff --git a/src/View/Helper/FormCollection.php b/src/View/Helper/FormCollection.php index 23b055d9..65452b57 100644 --- a/src/View/Helper/FormCollection.php +++ b/src/View/Helper/FormCollection.php @@ -8,7 +8,6 @@ use Laminas\Form\ElementInterface; use Laminas\Form\FieldsetInterface; use Laminas\Form\LabelAwareInterface; -use Laminas\View\Helper\Doctype; use Laminas\View\Helper\HelperInterface; use RuntimeException; @@ -25,7 +24,9 @@ class FormCollection extends AbstractHelper * @var array */ protected $validTagAttributes = [ - 'name' => true, + 'name' => true, + 'disabled' => true, + 'form' => true, ]; /** @@ -77,11 +78,6 @@ class FormCollection extends AbstractHelper */ protected $fieldsetHelper; - private array $doctypesAllowedToHaveNameAttribute = [ - Doctype::HTML5 => true, - Doctype::XHTML5 => true, - ]; - /** * Invoke helper as function * @@ -136,8 +132,12 @@ public function render(ElementInterface $element): string // Every collection is wrapped by a fieldset if needed if ($this->shouldWrap) { $attributes = $element->getAttributes(); - if (! isset($this->doctypesAllowedToHaveNameAttribute[$this->getDoctype()])) { - unset($attributes['name']); + if (! $this->getDoctypeHelper()->isHtml5()) { + unset( + $attributes['name'], + $attributes['disabled'], + $attributes['form'] + ); } $attributesString = $attributes !== [] ? ' ' . $this->createAttributesString($attributes) : ''; diff --git a/test/View/Helper/FormCollectionTest.php b/test/View/Helper/FormCollectionTest.php index e93e353b..b4033cec 100644 --- a/test/View/Helper/FormCollectionTest.php +++ b/test/View/Helper/FormCollectionTest.php @@ -411,7 +411,6 @@ public function testCanDisableLabelHtmlEscape(): void public function testForElementHelperNotInstanceOfHelperInterface(): void { $method = new ReflectionMethod(FormCollectionHelper::class, 'getElementHelper'); - $method->setAccessible(true); $this->expectException(RuntimeException::class); $this->expectExceptionMessage( @@ -458,8 +457,138 @@ public static function provideDoctypesAndPermitFlagForNameAttribute(): array [Doctype::HTML4_LOOSE, false], [Doctype::HTML4_FRAMESET, false], [Doctype::HTML5, true], - [Doctype::CUSTOM_XHTML, false], - [Doctype::CUSTOM, false], + ]; + } + + /** + * @dataProvider provideDoctypesAndPermitFlagForDisabledAttribute + */ + public function testRenderCollectionWithDisabledAttribute( + string $doctype, + bool $allowsNameAttribute, + bool $allowsShortAttribute + ): void { + $this->helper->setDoctype($doctype); + + $form = $this->getForm(); + $collection = $form->get('colors'); + $collection->setAttribute('disabled', true); + + $markup = $this->helper->render($collection); + + if ($allowsNameAttribute) { + if ($allowsShortAttribute) { + self::assertStringContainsString('