Make a generic email form processor

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:

All ColdFusion Tutorials By Author: D Evans
  • 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.
    Author: D Evans
    Views: 39,648
    Posted Date: Sunday, December 8, 2002
  • Trouble Shooting Cookies that work for you, One Possibility
    I had had created a login that used cookies to give access to an area of the web site. The owner of the web site could not login to the area using Windows NT, but upon testing I could always login with my windows 98 system. I could not figure out why the NT system would not login, but I could. It seemed to be a coding error by the site owner, since other sites could be logged in to. Some time later I stumbled upon the answer.
    Author: D Evans
    Views: 21,667
    Posted Date: Monday, December 9, 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.
    Author: D Evans
    Views: 26,479
    Posted Date: Wednesday, December 11, 2002
  • 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.
    Author: D Evans
    Views: 25,620
    Posted Date: Friday, December 13, 2002
  • 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.
    Author: D Evans
    Views: 26,856
    Posted Date: Friday, December 13, 2002
Download the EasyCFM.COM Browser Toolbar!