Skip to main content
Participating Frequently
July 29, 2011
Answered

Error when number sign # in address field of form

  • July 29, 2011
  • 1 reply
  • 2277 views

I need to be able to accept the number sign # in my form field for address, ie apt #3. When a # is submitted with my form, I get an error. How do I allow the # to be included for this field?

<cfinput style="WIDTH: 247px" size="30"  type="text" name="shipaddress" value="" required="yes" message="You must enter your address">

This topic has been closed for replies.
Correct answer Adam Cameron.

Yes. I was hoping to fix the # in the shipaddress, then look into these other areas of concern in the future. I don't want to start too many things at once. Could you suggest how I should use the escape function in my code?


Well...you don't say what you found (it would really help if you didn't assume we had telepathy...), but let's pretend it was urlEncodedFormat() you discovered.  Because that'd be the right function to use ;-)

So... having discovered that, have you read the docs for it?  http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7bdf.html

Have you just googled it to see any other examples in use?

Do you understand how CF functions work / are used (this might seem like a stupid question, but the wording of your post earlier makes me unsure... but ti could just be the wording... or my reading thereof).

Basically if you have a value in a URL which contains characters that are meaningful to the URL (like &, =, %, #, etc), you need to use urlEncodedFormat to convert the characters into a URL-safe encoded representation of them.

So if you had this value "here's a # sign" that you wanted to put in a URL, you'd need to use urlEncodedFormat() to escape it:

http://yourdomain.com/path/to/file.cm?param=#urlEncodedFormat("here's a # sign")#

Basically anything user-entered needs to be escaped, because you cannot predict what a user will enter...

--
Adam

1 reply

Owainnorth
Inspiring
July 29, 2011

When a # is submitted with my form, I get an error.

Okay, and what did the error say? When you get an issue like this, try and break it down to the smallest possible case people can test. As it's just a quickie, I knocked up this page:

<!--- test.cfm --->

<cfdump var="#form#">

<cfform>

  <cfinput style="WIDTH: 247px" size="30"  type="text" name="shipaddress" value="" required="yes" message="You must enter your address">

</cfform>

And when I put in "#3" and submit, it appears in my form scope just fine. I'm using CF9, so unless there are operational differences between my version and yours (which I doubt on something so small) the problem lies elsewhere. The hash symbol can cause issues (as it's a "reserved character" almost) so depending on how you're written your processing code it could cause problems.

Go through your code stripping it out line by line until you find the problem line.

O.

Inspiring
July 29, 2011

When a # is submitted with my form, I get an error.

Okay, and what did the error say?

Just to add my 2p here.  Every time one is thinking of making a post here about an error they are getting: give us the error message.

And before posting here: read the posting guidelines:

http://forums.adobe.com/thread/607238

Which are a distillation of this:

http://www.catb.org/~esr/faqs/smart-questions.html

To get back to the main question here though.  There is absolutely no special action one needs to take to allow a # sign in a form field value.  # signs have a special meaning in CFML source code (so could possibly need escaping in some situations), but not form submissions.

--

Adam

Owainnorth
Inspiring
July 29, 2011

There is absolutely no special action one needs to take to allow a # sign in a form field value.  # signs have a special meaning in CFML source code (so could possibly need escaping in some situations), but not form submissions.

My thinking is possibly there's an evaluate() being used, in which case it could cause problems and potentially need escaping.