-
Notifications
You must be signed in to change notification settings - Fork 87
Zend\Form\Fieldset bindValues problem #83
Comments
I'm hunting a bug that triggers in the same situation as this one and I tracked the source to exactly the same lines of Zend\Form\FieldSet in bindValues(). Notice that this is imho related to #106 #121 #122 and possibly to #95. The bug (or group of bugs) give all the same symptoms (object appears not bound) but they are sometimes related to extract() failing to get values or like in this case the actual bounding is not performed, but to final users they appear exactly the same. In my case I have a entity with a nested collection bound to a form with a fieldset that I am trying to update. Exactly as the case above.
IMHO the problems is that bindValues() is both called with $values in different "formats", one where it has $values from the form (so "names" are form names, e.g. "photoGalleries[0][title]") and the other case where $values is a more boring format with "plain" names (e.g. "title"). The above is somehow approximate, but is someone gives me some pointers and some more explanation I'm willing to dig a little on this. Imho a proper fix should really cover the two different cases (just for that if(), plus two for the above if from #122 ). |
@diniciacci Thanks! |
@froschdesign I failed up to now to produce one that fails indeed. I will try again. My customer said that the code was "perfectly working with old version of zf2". Where "old" is likely around 2.3.9 (zendframerowk version before the split). Will work on that in the following days. |
I am still working on the unit test. I am failing to reproduce the problem. However I found that InputFilterProviderFieldset->prepareElements() Line 368 in 4419eef
ends up calling setName() on the actual element (i.e. \Zend\Form\Element\Text) and so modifying its name to foo[0][bar] format (for nested elements, to avoid clashes). My theory is that then when binding happens the name have been modified and the $values can't match any of the names apart if the data comes from a form that has the above format. Naturally when calling bind data may come from different sources. I am progressing slowly due to unknown specifications of the code and some comments or suggestions would be welcome. Meanwhile I keep working on the unit test. I keep the good news for a later time when the test is ready. Best |
@froschdesign The PR has a unit test for this bug. The bug is not present in the current version. The bug was due to an interaction of prepare() with bindValues(). Notice that tests for the same interaction are missing for:
Thanks |
As a final note notice that c7867fe is the commit that introduced the fix and a test for it. Deciding if both tests should stay is beyond my knowledge of the code. |
Test for #83 bindValues not working after prepare
Hi.
Have next structure:
On validating form, In bindValues method we have name for title in PhotoGallery class like that: "photoGalleries[0][title]". But data array has not that key. He has key title. Array values look like:
['photoGalleries' => [0 => 'title']]
Source code (after update to version 2.8.4) in Zend\Form\Fieldset, row 568-569:
Source code (version 2.8.3) in Zend\Form\Fieldset:
Here we have correct name because it's taken from array. By the way in method extract we have same problem.
The text was updated successfully, but these errors were encountered: