Server Time:
Monday May 12 2008 07:07 AM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Make a generic email form processor
by: D Evans
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

Make a generic email form processor

This code will process any form submitted and email the submitted form fields excluding the submit, the redirect, the hidden, and the required fields; to the designated recipient.

This can be used for multiple web sites or multiple forms. The redirect is used to send the form user back to their own web site. I placed it in an accessible folder to all users, and gave them a Url to link to it if they wished to use the form. The redirect then had to contain a www.something.com to go back to their site. This makes it seamless.

For your own web site if you have multiple forms just refer the action to the place where you have the form processor. The url tag can then just have a page name you want them to go to after it is processed EX: index.html 

Or The url tag is optional. 


Create any html form.
Set the form action to go to your form processor file.

Make sure the form contains a required email field

Include 3 hidden fields:

recipient = who you want the email to go to
subject = the subject in the email you are sent
redirect = The page the form submitter is sent to after submission.

Ex:
<form action=”email_form.cfm” method=”post”>
   <input type=
“hidden” name=”recipient” value=”nyghtal@hotmail.com”>
   <input type= “hidden” name=”subject” value= “Add to email list”>
   <input type=
”hidden” name=”redirect” value=”www.mypage.com”>
   <input type=
”hidden” name=”email_required” value=”You must enter an email address to submit this form”>
   Name: <input type=”text” name=”yourname” value=””><br>
   Email Address: <input type=”text” name=”email” value=””><br>
   <input type=”submit” name=”submit” value=”Add me to your email list”>
</form>



3Of course this does need pretty formatting

Make the email_form processor file.

The if statement is used to exclude the hidden, required ,redirect and submit fields. To not submit any empty fields add or #fields# is "" to the if statement 


<cfmail to="#form.recipient#" from="#form.email#" subject="#form.subject#" type=”html”>
#form.subject# <br><br>
<cfloop index="thefield" list="#form.fieldnames#">
    <cfset fields=
"#thefield# = #evaluate(thefield)#">
    <CFIF #fields# contains "submit" or #fields# contains "required"
            OR #FIELDS# contains "recipient" or #fields# contains "subject" 
            or #FIELDS# contains
"redirect">

    <cfelse>
        #fields#<br>
    </cfif>
</cfloop>
</cfmail>


<cflocation url="#form.redirect#" addtoken="No">

Email Results:


Date added: Fri. December 13, 2002
Posted by: D Evans | Views: 17657 | Tested Platforms: CF5 | Difficulty: Intermediate
Categories Listed: Mail

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

This author's other tutorials:
Checking for submitted form fields
This sets all of the submitted form fields and values into a list then loops through the list of fields and values. - Date added: Fri. December 13, 2002
Frameless Frames in CF
The appeal of frames and the continued use is -- to leave one constant item on a part of the page. However clever, they are a pain to code, setting targets and defining the columns and then there that scroll bar thing. Here is an easy way to create the illusion of frames on your page. - Date added: Wed. December 11, 2002
Dynamic Image Gallery
You will be shown how to display the images in the desired number of columns and desired number of records per page with minimal coding. When the thumbnail image is clicked on it will open another window with the large image and image description under it. - Date added: Sun. December 8, 2002
Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
ColdFusion Hosting by HostMySite

You are 1 of 622 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb