RE: [PEAR] QF custom element creation

From: Date: Wed, 10 Dec 2003 14:05:27 +0000
Subject: RE: [PEAR] QF custom element creation
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-9452@lists.php.net to get a copy of this message
> -----Original Message----- > From: Alexey Borzov [mailto:borz_off@cs.msu.su] > > Hi! > > Mike Carter wrote: > > I was thinking of attempting to wrap up some small html/javascript > > things I'd written into Quickform elements. > > > > The single elements don't look too complex, I just wondered > if anybody > > has written a HOWTO for creating a new element from scratch. What > > classes do what, and maybe a little on the Quickform event mechanism > > maybe? > > I was planning to do such a guide for official QuickForm docs, but > haven't yet done this. :[ > Basically you'll need to consult > QuickForm/element.php --- base class for all elements > QuickForm/group.php --- group element, I presume you'll base your > elements on this > and > QuickForm/advcheckbox.php > QuickForm/date.php > QuickForm/hierselect.php > which can be considered as examples of custom elements At long last I have had some time to look at writing a custom element. I thought I would start off simple by replacing a common button I use within my QFController pages - a cancel button. The cancel button is derived from the 'button' element type. It all works fine too. My question is regarding making it more self-contained within the PHP code. The 'cancel' button element needs a javascript function which it calls on its 'onclick' attribute. I am, however, not to sure as to what is going on in the toHTML() method of hierselect.php So far I have the following code modified from the hierselect class:- function toHtml() { $this->updateAttributes(array('onClick' => "return decision('{$this->_options['message']}', '{$this->_options['location']}');")); if ($this->_flagFrozen) { $this->_js = ''; } else { if (!defined('HTML_QUICKFORM_CANCEL_EXISTS')) { $this->_js = "function decision(message, url){\n" ." if(confirm(message)) {\n" ." window.location.href = url\n" ." return true;\n" ." }\n" ." return false;\n" ."}"; define('HTML_QUICKFORM_CANCEL_EXISTS', true); } $this->_js .= "</script>\n"; } return $this->_js.parent::toHtml(); } // end func toHtml This works - however the way the javascript appears in the final HTML is a little odd. Looking at hierselect it never defines a " <script type="text/javascript"><!-- " before its javascript, instead just ending the jscript. With my code above, having no beginning <script> obviously means the jscript gets printed to the screen. My problem if probably small - I just wanted to know what the correct way to handle embedding javascript functions in element classes is. Thanks, Mike C. ________________________________________________________________________ This email has been scanned for all viruses by the MessageLabs Email Security System. For more information on a proactive email security service working around the clock, around the globe, visit http://www.messagelabs.com ________________________________________________________________________

« previous php.pear.general (#9452) next »