Attribute validation error with CFTEXTAREA

This post is more than 2 years old.

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

<cfform name="foo"> <cftextarea name="comments" value="Congrats Obama!"> </cftextarea> </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:

<cftextarea name="comments"> Congrats Obamas! </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:

<cftextarea name="comments" value="Congrats Obama!"></cftextarea>

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

<cftextarea name="comments" value="Congrats Obama!" />
Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Phillip Senn posted on 11/5/2008 at 7:08 PM

Oh! Oh! Mr. Kotter!

I thought it should be:
<cftextarea name="comments">Congrats Obama!</cftextarea>

Comment 2 by Raymond Camden posted on 11/5/2008 at 7:30 PM

Yeah, that's fine. I always trim() everything from the Form scope anyway. ;)

Comment 3 by Sarah posted on 11/18/2008 at 9:31 PM

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

Comment 4 by volumeone posted on 11/22/2013 at 4:03 AM

Thanks for this Raymond! Solved my issue today