
- Image via Wikipedia
Where we left off
If the first part of this short Coldfusion AJAX series, we discussed using the CFDIV tag, along with the CFAJAXIMPORT tag to enable us to dynamically load content into a div (cfdiv) layout container on the fly. The only custom javascript we made was to create a function that our href called to key the Coldfusion.navigate feature.
This time we will be discussing submitting forms asynchronously using Coldfusion, the CFDIV and CFFORM tags. This nifty feature allows web developers to submit their form within a containing div, and have the results of that form appear directly back to the user without reloading the entire page. In part three, the final installment, we will discuss how to build a search suggestion form control that dynamically populates a search text box as the user is typing.
CFDIV and CFFORM tags
We’ve already discussed the CFDIV tag, but now we discuss the CFFORM tag. The CFFORM tag is specific to Coldfusion and inserts forms into the page with server and client side processing, including built in validation for the tags contained within the form. Speaking of the tags within the form, they take on special characteristics and names, rather than using the input tag, we will be using the CFINPUT tag.
To ensure the form submits via AJAX we will simply enclose our form within a CFDIV container, keeping in mind that we need to include the proper tags via CFAJAXIMPORT. The other thing to note is on the CFDIV we are including the the page that contains our form as the bind parameter this time. The listing below is the complete listing for the form, note I have omitted the rest of the standard page elements (head, title, body etc.) for brevity. Provided you have your form handler script setup properly, in this case I called it formprocess.cfm in the example, the form will submit within the div.
Quick Code
<cfajaximport tags="cfform, cfdiv">
<cfdiv id="fomSub" name="formSub" bind="url:form.cfm">
</cfdiv></cfajaximport>
In the form.cfm file we would have the following:
Quick Code
<cfform action="formprocess.cfm" method="post>
<cfinput type=" text="" name="form1" id="form1" maxlength="45" size="20">
<cfinput type="submit" name="submit" id="submit" value="Submit">
</cfinput>
</cfform>
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=c98ee811-5fcf-4f3f-aa20-7eeeac041eae)
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=2b743204-6f88-437c-93b6-f50353ea70ab)


