For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > April 2005 > A HTML_QuickForm SubForm element type









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author A HTML_QuickForm SubForm element type
Justin Patrin

2005-04-13, 3:59 am

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', $subFo=
rm);
//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 =3D& HTML_QuickForm::createElement('subFormEl
ementName', '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.

--=20
Justin Patrin
Justin Patrin

2005-04-29, 3:58 am

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.
>=20
> http://fb.reversefold.com/SubForm.phps
>=20
> 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):
>=20
> require_once('HTML/QuickForm/SubForm.php');
> $form->addElement('subForm', 'subFormElementName', 'Sub Form Label', $sub=

Form);
> //NOTE: with this version $subForm is now a copy in the element so changi=

ng
> // $subForm now will not change the form within the element
>=20
> OR
>=20
> require_once('HTML/QuickForm/SubForm.php');
> $el =3D& HTML_QuickForm::createElement('subFormEl
ementName', 'Sub Form
> Label', $subForm);
> $el->setParentForm($form);
> $form->addElement($el);
>=20
> 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.
>=20
> This *should* also work for subforms within subforms. ;-) In fact, it doe=

s.
> http://fb.reversefold.com/SubFormTest.php
>=20
> If anyone uses this or has any ideas, please let me know.
>=20


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.

--=20
Justin Patrin
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com