Issues

ZF-10316: Form::isValid fails to populate elements when the name of the element may be filtered

Description

For example when using

$form->addElement('text','my-element');

calling $form->isValid($this->getRequest()->getPost() does not populate the element.

The problem is that the Element class internally calls filterName to set the name of the element (in this case converts 'my-element' to 'myelement'), but Form uses the name argument as passed as the key of the _elements array. In Form::isValid it iterates over the elements with foreach ($this->getElements() as $key => $element) {

and when $key doesn't correspond with posted name it fails to populate the element.

Comments

Patch fix and associated unit tests for this problem are attached.

Elaboration on my patch: There is no way to fix this while ensuring backwards compatibility. Up to other contributors to decide whether this is acceptable.

I think with some migration notes in docs we can add this to the 1.12 branch.