PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm_Controller » Bug #3582

new method HTML_QuickForm_Page::rebuildForm()

Details

Request #3582new method HTML_QuickForm_Page::rebuildForm()
Submitted2005-02-24 16:07 UTC
Frommflaherty at clearmessage dot com
StatusWont fix
PackageHTML_QuickForm_Controller
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2005-02-24 16:07 UTC] mflaherty at clearmessage dot com

Description:
------------
I would like to submit a method that I've written which I think would benefit the HTML_QuickForm_Page class. I use this method in classes that extend HTML_QuickForm_Page when an action handler alters the $page->_elements in some way and I would like $page->handle('display') to show the altered $page. This is essential when the $page form needs to be validated before calling the action handler, as validation requires the form to have already been built. Method rebuildForm() is careful to keep the automagical form elements such as _qf_default and _qf__FORM_NAME. In case there are any others I would suggest looping over the _elements property array to get the hidden fields with names matching /^_qf_/. I hope that at least someone will find this method useful. Thank you.

Reproduce code:
---------------
function rebuildForm() {
if ($this->isFormBuilt() ) {
$this->_formBuilt = false;
$pageName = $this->getAttribute('id');

// get the automagical form elements
$trackSubmitElem =& $this->_elements[$this->_elementIndex["_qf__{$pageName}"] ];
$defaultElem =& $this->_elements[$this->_elementIndex["_qf_default"] ];

$this->_elements = array();
$this->_elementIndex = array();
$this->addElement($trackSubmitElem);
$this->addElement($defaultElem);
}
return $this->buildForm();
}

[2005-02-24 16:38 UTC] mflaherty at clearmessage dot com

Sorry, I've described the problem incorrectly. This method would not seem to be useful for rebuilding an HTML_QuickForm_Page form after changes to the _elements array since this method actually clears the _elements array. It is useful however when conditions within buildForm() have changed and those changes would cause the form to be built differently, such as when an action handler has updated the container. This has a variety of applications.