Creating a simple contact form | Level: Easy | ColdFusion 7 (Tested)
Step 1 | The IF Statements
Quote:
<cfif IsDefined("form.Subject")>
</cfif>
|
The IF statements what until the form has been posted to then process the forms operations
Step 2 | The Form
Quote:
<cfform action="#CGI.SCRIPT_NAME#" method="post">
email <cfinput type="text" name="From" size="20"><br />
Subject <cfinput type="text" name="Subject" size="20"><br />
Message <textarea name="Message" cols="30" rows="3" ></textarea><br />
<input type="submit" value="Submit it" />
</cfform>
|
This is a standard sort of email form apart from the 'form' tags, you will notice they have 'cf' in front of the 'form' this tag now allows you to add more options to the form. These will be explained in another tutorial.
Step 3 | Processing the form
Quote:
<cfprocessingdirective suppresswhitespace="no">
<cfmail subject="#form.Subject#" from="#form.From#" to="EMAIL@EMAIL.COM" >
This is a message from that form...
#form.Message#
</cfmail>
</cfprocessingdirective>
|
The above the code processes the email form and send the email to who ever is listed in the 'to' and you can add 'cc' or 'bcc'
Full code
Quote:
<cfif IsDefined("form.Subject")>
<cfprocessingdirective suppresswhitespace="no">
<cfmail subject="#form.Subject#" from="#form.From#" to="EMAIL@EMAIL.COM" >
This is a message from that form...
#form.Message#
</cfmail>
</cfprocessingdirective>
<cfelse>
<cfform action="#CGI.SCRIPT_NAME#" method="post">
email <cfinput type="text" name="From" size="20"><br />
Subject <cfinput type="text" name="Subject" size="20"><br />
Message <textarea name="Message" cols="30" rows="3" ></textarea><br />
<input type="submit" value="Submit it" />
</cfform>
</cfif>
|
You can copy the full code into your coldfusion page which can be coldfusion 6+ including the new coldfusion 8 released by adobe. More advanced contact forms will be posted here later on.
Enjoy!
__________________
HostMediaUK : Low Cost Hosting | Linux PHP Hosting | Windows ColdFusion Hosting | ASP Hosting | Reseller Hosting | Dedicated Servers
AeonCube Networks : Web Design, ColdFusion Development and Web Hosting