zendframework / zend-form

Form component from Zend Framework
BSD 3-Clause "New" or "Revised" License
69 stars 87 forks source link

Dynamic elements are not validated #223

Closed wilariz closed 6 years ago

wilariz commented 6 years ago

Hi, I have an error in form validation when add a element(fieldset) dynamically and apply validationgroup.

errror messages:

File: /apps/bookingmotor/vendor/zendframework/zend-inputfilter/src/BaseInputFilter.php:484 Message: setValidationGroup() expects a list of valid input names; "Array" was not found

0 /apps/bookingmotor/vendor/zendframework/zend-inputfilter/src/BaseInputFilter.php(328): Zend\InputFilter\BaseInputFilter->validateValidationGroup(Array)

1 /apps/bookingmotor/vendor/zendframework/zend-inputfilter/src/BaseInputFilter.php(320): Zend\InputFilter\BaseInputFilter->setValidationGroup(Array)

2 /apps/bookingmotor/vendor/zendframework/zend-form/src/Form.php(513): Zend\InputFilter\BaseInputFilter->setValidationGroup(Array)

Code to reproduce the issue

Expected results

The message error indicate that Array name element no exist, this array corresponds to validationgroup of my dynamic element(fieldset). This "Array" should remove from the list to validate, it no happen beacuase the variable $inputs from Zend\InputFilter\BaseInputFilte class no contain the dynamic element added.

Actual results

This does not happen when element is defined in my form class.

froschdesign commented 6 years ago

For "dynamic" elements you can use the Collection element. A description and a tutorial can be found in the documentation: https://docs.zendframework.com/zend-form/element/collection/

For further questions please use the chat or the forum. Thanks!