RE: [PEAR] HTML_quickForm: Seperating JavaScript from html
| From: | Mark Steudel | Date: | Thu, 13 Oct 2005 15:20:49 +0000 |
| Subject: | RE: [PEAR] HTML_quickForm: Seperating JavaScript from html | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-21450@lists.php.net to get a copy of this message | ||
Thanks, here is what I came up with that seems to be working:
// display form
// $form is the quickform object
// $tpl is the Smarty Template object
function displayForm( &$form, &$tpl )
{
$javascript = $form->toArray();
$tpl->assign('javascript', $javascript[javascript]);
// remove empty tags for xhtml compliance
$html = str_replace( '<b></b>', ' ', $form->toHtml() );
// cut out the javascript that quickform generates
$html = preg_replace( '@<script[^>]*?>.*?</script>@si', '',
$html );
// display form
$tpl->assign('content', $html);
}
>-----Original Message-----
>From: Damien Cros [mailto:damienc@cc.in2p3.fr]
>Sent: Thursday, October 13, 2005 2:12 AM
>To: Mark Steudel
>Cc: PEAR general list
>Subject: Re: [PEAR] HTML_quickForm: Seperating JavaScript from html
>
>It gets all the javascript you could include in your <head>
>(<head><script>...</script></head>).
>
>However, it does not get the javascript which could be
>included in an element html tag.
>For instance, if quickform happens to build an element like
>this <element type="elementtype" onmouseover="javascript:...."
> or <a href="javascript:...."> then you'll have some javascript >in your
generated html file.
>
>Again, I don't know how every custom element type or every
>rule work, but as for the "classic" elements (input, select,
>...) and if you use server side validation, I think this won't happen.
>
>Look at the html generated source file and you'll see.
>
>Damien
>
>On 12 oct. 05, at 19:12, Mark Steudel wrote:
>
>>
>> Well I think it looks like it works :) When I do this, I'll
>just pass
>> all the JavaScript to a variable and assign it to a smarty variable
>> that's in my head. Thanks for the idea.
>>
>> I have a question:
>>
>> When you do this:
>>
>> $tFormData = $renderer -> toArray();
>> $tFormData['javascript']
>>
>> Does that get ALL the javascript created for all the elements? Or
>> would you need to loop through the array to get each elements
>> javascript?
>>
>> Mark
>> -----Original Message-----
>> From: Damien Cros [mailto:damienc@cc.in2p3.fr]
>> Sent: Wednesday, October 12, 2005 12:53 AM
>> To: Mark Steudel
>> Cc: 'PEAR general list'
>> Subject: Re: [PEAR] HTML_quickForm: Seperating JavaScript from html
>>
>> On 12 oct. 05, at 01:21, Mark Steudel wrote:
>>
>>
>>> I am looking for a way to easily separate the javascript from the
>>> body of the HTML generated from QuickForm and put it into
>the head. I
>>> am trying to use Smarty to accomplish this. I don't want to have to
>>> make a template for all of the forms as I like they way the
>look just
>>> fine. I just went to move the javascript from the body to the head.
>>>
>>> Thanks, mark
>>>
>>
>>
>> Hi Mark,
>>
>> Here's what I do to remove the javascript from the html generated by
>> quickform :
>> In my php file:
>>
>> $tFormData = $renderer -> toArray();
>> $Fnm = "js/quickform.js";
>> $inF = fopen ($Fnm , "w");
>> fwrite ($inF , $tFormData['javascript']); fclose ($inF);
>>
>> $tpl -> display('mytemplate.tpl');
>>
>> then of course i add the following line to my template:
>> <SCRIPT type="text/javascript"
>> src="js/quickform.js"></SCRIPT>
>>
>> I don't know if it works for *every* quickform element, though
>> (especially custom quickform element types) but at least it
>works for
>> me ;-) Also, I don't know if it's the nicest way to do it.
>What do you
>> think?
>>
>> bye
>> Damien
>>
>> --
>> PEAR General Mailing List (http://pear.php.net/) To unsubscribe,
>> visit: http://www.php.net/unsub.php
>>
>>
>
>