Re: HTML_QuickForm_Element accessing the HTML_QuickForm form name
| From: | Justin Patrin | Date: | Wed, 23 Feb 2005 17:38:55 +0000 |
| Subject: | Re: HTML_QuickForm_Element accessing the HTML_QuickForm form name | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-17652@lists.php.net to get a copy of this message | ||
On Wed, 23 Feb 2005 09:10:54 -0800, Justin Patrin <papercrane@gmail.com> wrote:
> On Wed, 23 Feb 2005 15:59:10 +0000, Ian P. Christian
> <pookey@pookey.co.uk> wrote:
> > I can't see how it's possible for an HTML_QuickForm_Element class to access
> > the name of the form which it belongs to.
> >
> > I've put some javascript into a form element which relies on the formanme
> > being known by some other included javascript, so the
> > HTML_QuickForm_Element::toHtml() mehtod calls some javascript to set some
> > variables. Anyway, all that is pretty irrelivent ;)
> >
> > does anyone know if there is a way for a HTML_QuickForm_Element to know the
> > name of the form? I would have thoguht that each element would comtain a
> > pointer to the form, but it doesnt' appear to.
> >
> > Any thoughts?
> >
>
> The only way I know if to get access to the form object is through
> onQuickFormEvent.
>
> class HTML_QuickForm_myEl extends HTML_QuickForm_element {
> //other stuff
> var $_formName;
>
> function onQuickFormEvent($event, $arg, &$caller) {
> switch ($event) {
> case 'createElement':
> $this->_formName = $caller->getAttribute($name);
> }
I just realized that my code was incorrect. :-| Move the parent call down here.
return parent::onQuickFormEvent($event, $arg, $caller);
> }
> }
However I also agree with Jamie. It's much better to not rely on the
form name. For instance, pass "this" into any JS events you fire to
get the current element. Then you should be able to get the form from
that (this.form).
>
> --
> Justin Patrin
>
--
Justin Patrin