Allow viewers to send you Feedback regarding your Site

In this tutorial, we will cover how to allow viewers send you feedback through a simple form and some coldFusion. It will consist of one page. We will not be using screenshots, just some code. We will also try to keep it moving fast, although still not prior ColdFusion knowledge is required. On your mark. Set. Go!


ColdFusion Get Feedback for your site.

Page 1, Page 2

We are basically done with the core code, since I chose to use the same page, we need to execute the code and Thank you only if the form is submitted and hide the form is so also.

6. Using isDefined(), let's see if the form is submitted and only then execute the code and the Thank you:

<cfif IsDefined("form.submit")>
<cfmail to = "omar@udnewbie.com"
from = "#form.txtFromEmail#"
Subject = "Feedback from Site"
type="HTML" >
#form.txtFeedback#
</cfmail>
<cfoutput>
Thank you <b> #form.txtFromName#</b>!<br>
You sent the following feedback:<br>
<b>#form.txtFeedback#</b>
</cfoutput>
</cfif>

Since we are using one page, we need to hide the form after it is submitted using NOT IsDefined():

7.
Manipulate the html for the form as such:

<cfif NOT IsDefined("form.submit")>
<form name="frmContact" Action="feedback.cfm" Method="Post">
Name <input type="text" name="txtFromName"><br>
Email <input type="text" name="txtFromEmail"><br>
Feedback <br><textarea name="txtFeedback" cols="40" class="textfields" rows="4"></textarea><br>
<input type="submit" name="submit" value="Send Feedback">
</form>
</cfif>


The Feedback is basically done!
We can add some tweaks now.

1. You can use Ultradev's built in validate form to validate the Email.

2. Recall we said earlier that some Web hosts do not allow outgoing mail from Email Domains not hosted with them. If you ran into this problem, we can inform ourselves who submitted the Feedback by tweaking the Mail Code: go back to the mail code and add this in the body:

<cfmail to = "omar@udnewbie.com"
from = "#form.txtFromEmail#"
Subject = "Feedback from Site"
type="HTML" >
#form.txtFeedback#
<p>
This feedback was submitted by: <a href="mailto:#form.txtFromEmail#">#form.txtFromName</a>
</cfmail>


3. What if the viewer submits the form without entering an Email or any feedback? Let's make sure this doesn't happen. We place the code after checking if the form is submitted.

<cfif IsDefined("form.submit")>
<cfif #form.txtFromEmail# is "" OR #form.txtFeedback# is "">
Please go back and fill the entire form.
<cfelse>

<cfmail to = "omar@udnewbie.com"
from = "#form.txtFromEmail#"
Subject = "Feedback from Site"
type="HTML" >
#form.txtFeedback#
</cfmail>
<cfoutput>
Thank you <b> #form.txtFromName#</b>!<br>
You sent the following feedback:<br>
<b>#form.txtFeedback#</b>
</cfoutput>
</cfif>
</cfif>


See the complete code here


Happy Programming!

Omar Elbaga
UDnewbie.com
If you have any problems with this tutorial, just drop me an email or post in the Ultradev newsgroup.

Omar Elbaga

Starting out as a fine artist, Omar Elbaga gradually moved to computer graphic arts. He was particularly amazed by the power of the World Wide Web, so he embarked upon building small-scale sites for fun utilizing HTML and his Art background. Falling in love with designing web pages and its potential, he began a career in web design. Omar has since been in the web development field for several years. With his head in computer books nearly 24 hours a day, Omar moved on to enhance his skills from web design to web programming.

Most of his work involves building database-driven web sites for small companies. Omar is currently running a popular Dreamweaver MX resource site named dmxfire.com

See All Postings From Omar Elbaga >>

Comments

Be the first to write a comment

You must me logged in to write a comment.