Re: Help with extending HTML_QuickForm_select

From: Date: Sat, 05 Feb 2005 10:48:51 +0000
Subject: Re: Help with extending HTML_QuickForm_select
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-35955@lists.php.net to get a copy of this message
Justin Patrin wrote: >On Fri, 04 Feb 2005 16:52:54 -0800, Jamie Alessio ><Jamie.Alessio@ucop.edu> wrote: >> The javascript is not a problem, but this requires that I add the >> "onsubmit" attribute to the <FORM> tag and I'm struggling with how to >> properly do this within the structure of HTML_QuickForm. As far as I can >> tell the only chance that a class that extends HTML_QuickForm has to >> modify the attributes of the the <FORM> tag is via the $caller variable >> in the onQuickFormEvent($event, $arg, &$caller) method in my inherited >> class. The only way I have gotten this to work so far is by catching >> when onQuickFormEvent() is called with an 'addElement' event and doing >> something like this: >> >> $caller->updateAttributes(array( >> 'onsubmit' => "javascript: myJsFunction(blah)")); >> >> Is this a *correct* way to do this? Can I reliably count on being able >> to set this during the 'addElement' event? Any thoughts on a better way >> to have a subclass of HTML_QuickForm modify the attributes of the <FORM> >> tag that the element is going to be a member of? > >This sounds like the "correct: way of doing this, but.... Yes, this is the way to go. >> You can view an example of how this is currently working at >> http://jalessio.com/pear/advmultselect.php and please let >> me know if you >> have any problems with this in your browser of choice. >> > >I would suggest you instead have another (hidden) box with the >selected values in it *and* selected. Or create a hidden element with >the values for each selected value. This way you don't have to rely on >an onsubmit. The problem with onsubmit is it can be overriden if the form uses javascript validation. More checks could be done in addRule() to see if there is already an onsubmit attribute set, and append to it ? The hidden element idea sounds good but how would you make the result look like an array once the form is submitted ? Bertrand

« previous php.pear.dev (#35955) next »