Re: preGenerateForm questions [FormBuilder]
| From: | Justin Patrin | Date: | Wed, 23 Jun 2004 19:34:05 +0000 |
| Subject: | Re: preGenerateForm questions [FormBuilder] | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13284@lists.php.net to get a copy of this message | ||
On Wed, 23 Jun 2004 14:20:50 -0500, Sarah Gray <sarah@fabled.net> wrote:
>
> Yeah, maybe I did need postGenerateForm which I was using already. That worked
> for the updateElementAttr call, so thanks.
>
> I am still experiencing the issue where when I create a group in
> postGenerateForm, it is appended
> to the form rather than replacing the specific elements that are in the group.
> I'd love to know how to add elements to the group and have the group rendered
> without *also* rendering the same elements outside of the group.
>
> I thought this would work
> $name[] = $form->getElement(first_name);
> $name[] = $form->getElement(last_name);
> $form->addGroup($name, 'nameGrp', 'Name Please');
You should be doing:
$name[] =& $form->getElement('first_name');
Note the & and the ' '.
You may also need to remove the old element from the form, but I'm not sure....
It will still be added to the end of the form because that's how
QuickForm works. I've submitted a patch to allow moving of elements.
Check it out (and voice your support) in the bug report:
http://pear.php.net/bugs/bug.php?id=1587
>
> but it duplicates those elements and renders them twice. Hm.
>
> Thoughts or experience on this?
>
> Thanks,
>
> Sarah
>
> PS. An example of preGenerateForm in action would help clarify my
> misunderstanding of its usage, if someone has a sec to post one I'd appreciate
> it.
>
There's no examples, but the docs I added recently explain it. Here's
what they say:
preGenerateForm():
This method will be called before the form is generated. Use this
to change property values or options in your DataObject. This is where
you should set up preDefElements.
>
>
>
> Justin Patrin wrote:
>
> > This function is called before the form is generated and does not pass
> > the form in. I think you want postGenerateForm(&$form).
> >
> > For more docs, check the newest CVS version:
> >
> > http://cvs.php.net/co.php/pear/DB_DataObject_FormBuilder/FormBuilder.php
> >
> > Also, we're likely to be introducing lots of BC breaks in the next
> > release so that we can clean up the code before the first stable (1.0)
> > release. Mostly, this will just be renaming / moving of options and a
> > little bit of different option formatting. All of the options will
> > behave the same way, though. :-)
> >
> > On Wed, 23 Jun 2004 14:00:17 -0500, Sarah Gray <sarah@fabled.net> wrote:
> > >
> > > Hi,
> > >
> > > Can someone post an example of preGenerateForm() in action?
> > > I've been getting errors when using it (it's in the DO). Think I've
> > > got
> > > the syntax wrong.
> > >
> > > function preGenerateForm(&$form){
> > > $form->updateElementAttr('first_name',
> > > 'onchange="hello();"');
> > > }
> > >
> > > [I tried it in a bunch of other configurations, passing $do and $fg and
> > > nothing -- but no luck. So I'm missing something].
> > >
> > > erro: Call to undefined function: updateelementattr()
> > >
> > > Anyway, I'd like to use preGenerateForms for a few things
> > > (that I can do for the most part when *not* using it).
> > >
> > > 1. Attach special javascript events to specific elements (example
> > > above). Works fine outside function as such:
> > >
> > > $form->updateElementAttr('first_name',
> > > 'onchange="hello();"');
> > >
> > > 2. Create element groups so that I can apply styles later on. This I
> > > can do fine outside of preGenerateForm -- but my group is created IN
> > > ADDITION
> > > to the elements in the form and appended to the end of the form. How
> > > would I create that so
> > > that it renders in the right order in the render -- ie, replaces the
> > > original elements not duplicates them at the end?
> > >
> > > This is my "working" but appending-not-replacing code:
> > > $name[] = $form->getElement(first_name);
> > > $name[] = $form->getElement(last_name);
> > > $form->addGroup($name, 'nameGrp', 'Name Please');
> > >
> > > 3. Also -- if I wanted to pass along a piece of info with each element
> > > that I could use when rendering, how would I do it?
> > > Specifically I'd like to be able to have an element know if it was going
> > > to be colspan 1, 2, etc. (And not have it dependent on the
> > > element.type). Thoughts on passing xtra info with the elements that I
> > > can parse in the renderer? Or should I just do this using style groups?
> > >
> > > Thanks in advance,
> > >
> > > s.
> > >
> > > --
> > > PEAR General Mailing List (http://pear.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
> > --
> > --
> > paperCrane <Justin Patrin>
>
>
--
--
paperCrane --Justin Patrin--