My code looked like that:
php $this -> map('names', new opfArrayContainer( new opfConstraint(MAP_TYPE, TYPE_STRING), new opfConstraint(MAP_LEN_GT, 2) ), OPF_OPTIONAL); $this -> map('surnames', new opfArrayContainer( new opfConstraint(MAP_TYPE, TYPE_STRING), new opfConstraint(MAP_LEN_GT, 2) ), OPF_OPTIONAL); $this -> map('pesels', new opfArrayContainer( new sConstraint(MAP_PESEL) ), OPF_OPTIONAL);
In other words, the script must have received for example the "names" field, which was an array of 30 elements with the names. If the user made a mistake while filling in the form, the form renderer did not have a clue, which component to display as invalid (in this case it should be colored red instead of green). Finally, I added a support for the IGNORE_OPF_ERRORS constant so that shut it up and just display everything without all this color rotation stuff.
Of course, it is not possible to keep this problem unsolved in the "public" releases and I decided to look for solution. It would be nice, if the improvement easily matched to the code, as well as was intuitive. It's not a problem to add something in 20 minut and a month later self-wishing a rapid death. The best solutions are simple and effective, so I started to think, how to describe a form with some definitions and transformations, so that it would be possible to construct every form and process it with OPF. My idea is to go somewhere deeper and remove distinguishing between forms and form elements. The reasons:
- Both have a value (in the form case we define it as a set of subelement values).
- Both have a state.
- Both can be processed.
Now we can easily treat a form as an element which is capable of storing other fields. If we try to build our form described above, it will look like this: we create a form for a single person: name, surname, PESEL, etc. Next, we put it into a bigger form and order to loop up to 30 times. We can also achieve an effect of looping a single field, like it was possible with opfArrayContainer() so far. We just put in such loop not a form, but a single element.
Well, now the problem is, how to render it :). However, I don't think it will be complicated, especially if I look at the new Open Power Template.