Attribute validation error with CFTEXTAREA

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 developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA