ColdFusion FAQ
Sure, use the <cfheader> tag to let the browser know that it is working with a file, instead of an HTML page:
<cfheader name="Content-Disposition" value="attachment; filename=newdocument.doc">
<cfcontent type="application/msword" file="/home/me/a2928axa~123.doc">
The type attribute specifies the mime type of the file, click here for a list of mime types.
How do I insert the Current Date into Database?
Depending on your database server (SQL Server, MySQL, PostgreSQL, Oracle, etc..), you can use code similar to the following:
<cfquery datasource="mydatabase">
INSERT INTO table (field1, date) VALUES ('#field1value#', '#DateFormat(Now(), "yyyy-mm-dd")#')
</cfquery>
Of course, an even easier way to accomplish this is to make the date field in the database a TIMESTAMP field. In effect, this will update the field to the current date and time each time you modify the record.
Which Development Tool should I use to develop ColdFusion applications?
I personally have progressed through using a text editor, to using Dreamweaver, and finally to Eclipse. Download Eclipse at http://www.eclipse.org. Once you install, go to the help menu and choose Software Updates->Find and Install. Add this site http://cfeclipse.tigris.org/ and you'll be on your way. Stick with Eclipse if you can get used to the interface. It is free, plugins are readily available for a number of languages, and best of all, it is fast.
Accessing data in Nested Query Loops
When using nested loops to extract data from recordsets, you will come into a complication when you try to access information using the standard ColdFusion method of surrounding the fieldname with pounds signs:
This does not work:
<cfloop query="q1">
<cfloop query="q2">
<cfoutput>#q1fieldname#</cfoutput>
</cfloop>
</cfloop>
This does work:
<cfloop query="q1">
<cfset q1fieldname_temp = q1fieldname>
<cfloop query="q2">
<cfoutput>#q1fieldname_temp#</cfoutput>
</cfloop>
</cfloop>
ColdFusion Email Validation
Using regular expressions, you can easily validate emails with ColdFusion using the following regex:
<cfif REFindNoCase("^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$", form.email) eq 0>
<cfset validEmail = false>
</cfif>
Need assistance with your project? Universal Web Services can help.
Contact us to request a quote.