> Thanks! That fixed that problem. I have another one
> now....

> If I call a file like this...

> <cffile action="READ" file="#page#" variable="output">

> .. then display it like this....

> <textarea
> name="contents"><cfoutput>#output#</cfoutput></textarea>

> .. I run into a problem if the variable output has a
> textarea tag contained
> within it.

<snippage>

Say no more... I had to deal with this issue with my CMS application. It's
the same problem that occurs with text fields and users entering
double-quotes where you've used something like

<input type="text" name="blah" value="#myvalue#">

To the browser (because variable output / evaluation occurs on the server),
this appears as though you've simply typed in

<input type="text" name="membername"
  value="Jim "the Man" Davis">

or

<textarea name="mytemplate">
  <textarea name="something else">
</textarea></textarea>

Of course, because of the nature of html and browsers, you already know what
happens: The browser see's the double-quote and ends the attribute or the
</textarea> and ends the textarea...

The way around this is to create the form first, then populate the values
_after_ the form has finished rendering, using javascript. The qForms API (
http://www.pengoworks.com ) can make this a much simpler process... For
instance,

<form name="myform">
  <textarea name="mytemplate"></textarea>
</form>

<script language="javascript" type="text/javascript">
  function loadMyForm() {
    document.myform.mytemplate.value = "#jsstringformat(myvalue)#";
  }
</script>

Something like this works okay, but every time you add a text field or a
textarea to the form, you also have to add lines of javascript. With qForms
and a tiny bit of wddx it's possible to populate a 500 field form with the
same half-dozen lines it takes to populate a 5 field form. I.e.:

<form name="myform">
  <textarea name="mytemplate"></textarea>
</form>

<cfloop index="x" list="#myquery.columnlist#">
  <cfparam name="form.#x#" type="string"
    default="#myquery[x][1]#" />
</cfloop>

<script language="javascript" type="text/javascript">
  function loadMyForm() {
    theform = new qForm("myform");
    <cfwddx action="cfml2js" input="#form#"
      toplevelvariable="formdata" />
    theform.setFields(formdata);
  }
</script>

Gotta love reusable code. :)

One caveat -- the <cfwddx> call will jsstringformat everything accept an
instance of </script> ( in which case, you run into the same problem you had
before with the form fields ) ... You can escape </script> as something like
<\/script> but you can't do it prior to the cfwddx call, and since the
cfwddx call outputs directly to javascript, this means if you need to allow
javascript blocks within your textarea, then you'll have to convert your
variables to javascript manually. Which isn't too tough -- just replace the
cfwddx tag with this:

formdata = new Object();
<cfloop item="x" collection="#form#">
  formdata["#jsstringformat(x)#"]
    = "#ReplaceNoCase(jsstringformat(form[x]),
      "</script>","<\/script>","ALL")#";
</cfloop>

Sorry about the line breaks, you know, email and all... :)

hth

s. isaac dealey                954-776-0046

new epoch                      http://www.turnkey.to

lead architect, tapestry cms   http://products.turnkey.to

certified advanced coldfusion 5 developer
http://www.macromedia.com/v1/handlers/index.cfm?ID=21816


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

Reply via email to