Re: A HTML_QuickForm SubForm element type

From: Date: Thu, 28 Apr 2005 23:55:53 +0000
Subject: Re: A HTML_QuickForm SubForm element type
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19007@lists.php.net to get a copy of this message
On 4/12/05, Justin Patrin <papercrane@gmail.com> wrote: > I've created a "subForm" element type for HTML_QuickForm which takes > any HTML_QuickForm and makes it an element in another form. > > http://fb.reversefold.com/SubForm.phps > > A few caveats: this element *must* be either created by a call to > addElement on your main form (with the construction parameters, not an > element object) or you must call setParentForm on the element. If you > don't, the rules on the subform won't work. Here's the two usages > (assuming $form is the main form and $subForm is the sub-form): > > require_once('HTML/QuickForm/SubForm.php'); > $form->addElement('subForm', 'subFormElementName', 'Sub Form > Label', $subForm); > //NOTE: with this version $subForm is now a copy in the element so changing > // $subForm now will not change the form within the element > > OR > > require_once('HTML/QuickForm/SubForm.php'); > $el =& HTML_QuickForm::createElement('subFormElementName', 'Sub Form > Label', $subForm); > $el->setParentForm($form); > $form->addElement($el); > > This also uses a few hacks which access HTML_QuickForm internals which > is a no-no, but it's the only way I could get unfreeze and > setPersistentFreeze to work as HTML_QuickForm doesn't implement these > functions (perhaps these should be added?). This *should* work with > any renderer, but I haven't tested it and I modeled it on the default > renderer, so it could quite easily not work with other renderers. > However, it should work with customizations of the default renderer. > > This *should* also work for subforms within subforms. ;-) In fact, it does. > http://fb.reversefold.com/SubFormTest.php > > If anyone uses this or has any ideas, please let me know. > Just in case anyone has started using this, I just fixed a bug with the validation which caused validation to return an error when the pre validation callback returned false. -- Justin Patrin

« previous php.pear.general (#19007) next »