Re: QFC - how do you validate and then buildForm() ?
| From: | Matt Flaherty | Date: | Thu, 24 Feb 2005 14:55:23 +0000 |
| Subject: | Re: QFC - how do you validate and then buildForm() ? | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-17673@lists.php.net to get a copy of this message | ||
Alexey Borzov wrote:
Hi, Matt Flaherty wrote:----%<---- function rebuildForm() {This is my first post to this list (I think). I have a custom QFC action whose effect is to alter the way the form is built. I do not want to process the action unless the form is valid though, but this requires me to build the Page first using Page::buildForm(). This poses a dilemma, as no matter what I try I can not seem to rebuild the Page differently to the way it was first built. Does anyone have a workaround? Much appreciated.I suggest making *two* different pages, triggered by this particular action. IIRC, there is an example for this in QFC. Thanks. That's a good suggestion. My QuickForm has fields dynamically added to or removed from it as a result of a custom action handler, so that would not work (unless I have misunderstood). Here's the solution I came up with as a method on a class extending HTML_QuickForm_Page:
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();
}
----%<----
I've found this does the trick nicely.