2

I have a form that users will copy and paste text from a word doc. This content may include a tab character. An on-click function handles the form submission using JSMX ajax call to a coldfusion remote function. The form is passed through the ajax call to the component.

<form name="test">
<textarea name="swPurpose"></textarea>
<input type="button" value=" Go " onclick="goForm(this.form);" />
</form>

function goForm(f){
var param=f; 
http('POST','testCFC.cfc?method=test',goForm_RTN,param);
}

<cfcomponent output="false">
<cffunction name="test" access="remote" output="false">
<cfset rtn=structNew()/>
<cfsavecontent variable="rtn.html">
<cfoutput><p>#form.swPurpose#</p></cfoutput>
</cfsavecontent>
<cfreturn rtn />
</cffunction>
</cfcomponent>

This works very well unless a tab character is in the form content. If a tab in the content, I get a 500 Internal Server Error.

This is sample text submitted in the form.

1   This is text
2   This is text
3   This is text

This is the encoded text from Firebug that is posted to the function.

swPurpose=1%9This%20is%20text%0a2%9This%20is%20text%0a3%9This%20is%20text&btn=%20OnClick%20,%20Submit%20

Using Firebug, I can see the content posted to the function is encoded. Tabs are %9. I can put the cfc in the action of the form and the function doesn't fail.

My workaround is to strip out the tabs using javascript before sending it to the function. However, I would like to understand why the tab is causing the 500 error and if there is anything that can be done to prevent this.

garyv
  • 187
  • 1
  • 9

2 Answers2

0

Try this code:

function goForm(f){
    var param = escape(f);//Or also encodeURI(f) or even encodeURIComponent(f)
    http('POST','testCFC.cfc?method=test',goForm_RTN,param);
}
Danilo Valente
  • 11,270
  • 8
  • 53
  • 67
0

You can replace out the tabs with a simple regex in the CF code before handing back.

<cfcomponent output="false">
    <cffunction name="test" access="remote" output="false">
        <cfargument name="form">
        <cfset var rtn=structNew()/>

        <cfsavecontent variable="rtn.html">
            <cfoutput><p>#ReReplace(form.swPurpose, "\t", "&nbsp;&nbsp;", "ALL")#</p></cfoutput>
        </cfsavecontent>
        <cfreturn rtn />
    </cffunction>
</cfcomponent>
Sharondio
  • 2,605
  • 13
  • 16
  • Don't need regex for this, just `replace(text,chr(9),"  ","all")` will do. (Although I doubt this is the right way to deal with the problem here.) – Peter Boughton May 10 '12 at 16:01
  • The 500 internal server error doesn't allow any CF solution. The error is occurs before any CF code can be processed. My workaround had to happen at the client before the form content with the tab character was sent to the server. – garyv May 11 '12 at 15:57