XML forms and CFIMAGE

I was working with Dan Plesse on an odd issue he had with CF8 Image Captcha’s and CFFORM. No matter what he did, he couldn’t get the captcha to show up in the form. My first though was a broken CFIDE or some other ‘special’ folder, but that wasn’t the case. If we viewed source on his page, there was no IMG tag at all. I finally got it down to one very simple example: <cfform name="register" id="register" format="XML" skin="blue" style="border-left-style:groove; padding:0px; width:auto" enctype="multipart/form-data" action="<cfoutput>#CGI.script_name#</cfoutput>" method="post" > <!--- Use cfformgroup to put the first and last names on a single line. --->

<cfformgroup type=”vertical” label=”Step 4 - captcha “>

&lt;cfinput type="text" name="captcha_test"  value="" size="7" label="Enter text that  you see in the image:" /&gt; &lt;img src="http://images.pcworld.com/images/header/logo_hd.jpg"&gt;

&lt;cfimage
   action="captcha"
   height="60"
   width="200"
   text="moon pies"
   difficulty="low"
   fonts="verdana,arial,times new roman,courier"
   fontsize="15"   /&gt;

</cfformgroup>

</cfform> </code>

I finally figured out that the issue was with the format=”xml”. When I removed that, it worked perfectly.

And then I did something magical. I actually read the docs on XML forms. (This is a feature in ColdFusion I’ve never used in production, nor have I played with it much.) The docs clearly say that any non-form items will be stripped. To keep them in…

ColdFusion does not process inline text or standard HTML tags when it generates an XML form; therefore, you use the cfformitem tag to add formatted HTML or plain text blocks and any other display elements, such as horizontal and vertical rules, to your form.

So taking the above code, we can fix it right away like so:

<cfform name="register" id="register" format="XML" skin="blue" style="border-left-style:groove; padding:0px; width:auto" enctype="multipart/form-data" action="<cfoutput>#CGI.script_name#</cfoutput>" method="post" > <!--- Use cfformgroup to put the first and last names on a single line. --->

<cfformgroup type=”vertical” label=”Step 4 - captcha “>

&lt;cfinput type="text" name="captcha_test"  value="" size="7" label="Enter text that  you see in the image:" /&gt; &lt;img src="http://images.pcworld.com/images/header/logo_hd.jpg"&gt;

&lt;cfformitem type="html"&gt;
&lt;cfimage
   action="captcha"
   height="60"
   width="200"
   text="moon pies"
   difficulty="low"
   fonts="verdana,arial,times new roman,courier"
   fontsize="15"   /&gt;
&lt;/cfformitem&gt;

</cfformgroup>

</cfform> </code>

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. You can even buy me a coffee!

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

Comments