A HTML_QuickForm SubForm element type
| From: | Justin Patrin | Date: | Wed, 13 Apr 2005 05:02:42 +0000 |
| Subject: | A HTML_QuickForm SubForm element type | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-18714@lists.php.net to get a copy of this message | ||
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.
--
Justin Patrin