Raymond Camden's Blog Rss

Attribute validation error with CFTEXTAREA

3

Posted in ColdFusion | Posted on 11-05-2008 | 2,995 views

Here is an interesting little issue a reader ran into this week. Can you tell me why the following code throws an error?

view plain print about
1<cfform name="foo">
2<cftextarea name="comments" value="Congrats Obama!">
3</cftextarea>
4</cfform>

The error that is thrown is:

Attribute validation error for the CFTEXTAREA tag.

The value of the VALUE attribute cannot be defined twice. ''

Seems rather odd, doesn't it? There is clearly only one value attribute above. But the reader forgot that normally, the value of a textarea is defined between the beginning and end tag, like so:

view plain print about
1<cftextarea name="comments">
2Congrats Obamas!
3</cftextarea>

Because his code had a line break between the start and end tag, ColdFusion considered that white space to be a value, and threw an error. Personally I think ColdFusion could just do a quick trim() check if it has an value attribute, but the fix is easy enough. You can move the value between the tags as I have before. Or you can remove the line break:

view plain print about
1<cftextarea name="comments" value="Congrats Obama!"></cftextarea>

And lastly, you can just use a shorthand notation for the closing tag:

view plain print about
1<cftextarea name="comments" value="Congrats Obama!" />

Comments

[Add Comment] [Subscribe to Comments]

Oh! Oh! Mr. Kotter!

I thought it should be:
<cftextarea name="comments">Congrats Obama!</cftextarea>
Yeah, that's fine. I always trim() everything from the Form scope anyway. ;)
Thanks for this info, it solved one problem I have, but not a second, loosely related, one.

Does anyone have problems with form validation failing on cftextarea where fckeditor is enabled? I get the validation alert that for all the fckeditor fields upon submit (even though the fields contain valid data), but if I immediately submit again, the form submits. Any idea why I have to submit twice? Tia, Sarah