Home » Database » DB_DataObject_FormBuilder » Bug #4440
Appended forms does not contain rules and errors
Details
| Submitted | 2005-05-26 11:04 UTC |
|---|---|
| From | php at pinna dot nl |
| Assigned | justinpatrin |
| Status | Closed |
| Package | DB_DataObject_FormBuilder |
| PHP Version | 5.0.3 |
| OS | np |
| Roadmaps | (Not assigned) |
Comments
[2005-05-26 11:04 UTC] php at pinna dot nl
Description:
------------
The problem is that when you append a form via useForm(), the validated rules and appeared errors are ignored...
I found that out in a form with the same elementNames with another elementPrefix, so I first thought that was the problem...
I digged deep into the original QuickForm.php but nothing found there...
anyway, I found out that, (damn I should have started there) the problem was in the appending process. There only elements get appended but not rules, and since these rules are appended in the getForm process....these are ignored.
I made a quick solution of which i think does the job
Reproduce code:
---------------
//APPEND EXISTING FORM ELEMENTS
if (is_a($this->_form, 'html_quickform') && $this->_appendForm == true) {
// There somehow needs to be a new method in QuickForm that allows to fetch
// a list of all element names currently registered in a form. Otherwise, there
// will be need for some really nasty workarounds once QuickForm adopts PHP5's
// new encapsulation features.
reset($this->_form->_elements);
//////////////ADDED BY JAN@PINNA.NL
/**
* To maintain rules from appended forms.
*
*/
$orgErrors = $this->_form->_errors;
$orgRules = $this->_form->_rules;
$curErrors = $form->_errors;
$curRules = $form->_rules;
$form->_errors = array_merge($orgErrors,$curErrors);
$form->_rules = array_merge($orgRules,$curRules);
////////////ADDED BY JAN@PINNA.NL
while (list($elNum, $element) = each($this->_form->_elements)) {
$this->_addElementToForm($form, $element);
}
}
Expected result:
----------------
replace code with:
//APPEND EXISTING FORM ELEMENTS
if (is_a($this->_form, 'html_quickform') && $this->_appendForm == true) {
// There somehow needs to be a new method in QuickForm that allows to fetch
// a list of all element names currently registered in a form. Otherwise, there
// will be need for some really nasty workarounds once QuickForm adopts PHP5's
// new encapsulation features.
reset($this->_form->_elements);
while (list($elNum, $element) = each($this->_form->_elements)) {
$this->_addElementToForm($form, $element);
}
}
[2005-05-26 19:54 UTC] php at pinna dot nl
Well, that doesnt really do the job for autorules...
I made an enhancement on formbuilder for myself (just experimental) to get the constraints from my pgsql database and add them to the form. This works like a charm and makes it possible to very easily do a proof-of-concept of a datamodel...
Now I ran into this problem because I wanted to create a listview of a form, with multiple rows. Therefore I already tackled the vertical orientation of the form.
With appendForm I can manage that all fields are filled automatically and validation also... This makes it very versatile, at least for me in this experiment..
I hope you keep the appendForm.. Maybe a request for public methods for rules and errors can be made..?
Maybe the autorules can be transferred easily because that is manage by FormBuilder... just a thought.
[2005-05-27 07:09 UTC] php at pinna dot nl
Ai caramba....
That looks a lot better... I see now what you mean. Somehow, first without append=true it didn't work properly. Now it does...
Sorry for this and thanks for the help.
It's a bit confusing for me that appending=false does not mean that the form isnt merged with/added to the other form. Maybe remove append indeed.. :)