Adding multiple actions to a form

I have a Coldfusion form, commentform.cfm, which is used to collect information from a user and input that data into a database then subsequently open a thankyou.cfm page which thanks the user and redirects them to another page. The data is input to the database using the Insert Record Server Behavior. Everything works fine.

Now I would like to add two features:
1. When the user inputs their information to specific fields that appear on commentform.cfm, for example, their first name which they input to the fname field, I would like to create a cookie so that when the user returns to commentform.cfm, the fname field is already completed for them.
2. When the user presses the submit form, which inputs a new record to the database, I would like to have an email sent to myself so that I know a record has been added to the database.

From what I've read on the subject, I think that I can set the cookie by placing the code
<cfcookie name="fname" value="#FORM.fname#">
in the thankyou.cfm page and have the commentform.cfm form action set to post to thankyou.cfm. But when I look at the existing form tag code as it is in commentform.cfm, it reads:
<form action="<cfoutput>#CurrentPage#?#CGI.QUERY_STRING#</cfoutput>" method="POST" name="frm_comment" id="frm_comment" onsubmit="MM_validateForm('email','','NisEmail');return document.MM_returnValue">
Being a novice in Coldfusion, I don't want to destroy the successful functionality of my form as it is now since it does what I need it to do but I am afraid to try to add another action attribute to my form because I cannot find any documentation that says I can do that and I don't know any other way to create that functionality.

In addition, I don't know how to code the email that I would like sent to myself or how I would also add that function to the submit button.

Might anyone help?

Thanks,
Lee
lepirtleAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
kyle1830Connect With a Mentor Commented:
sure
<cfoutput>      
   <script language="JavaScript">
               {
               window.location="thankyou.cfm?&#CGI.QUERY_STRING#";
               }
               //  End -->
          </script>  
</cfoutput>
0
 
kyle1830Commented:
From looking at your code the form seems to be submitting to itself.  Unless the var #CurrentPage# is set to something else.

If it is the same form after you do the insert
<cfcookie name="fname" value="#FORM.fname#" expires="never">
<cfmail to="myemail@mydomain.com" from="myemail@mydomain.com" server="mail.mydomain.com" subject="New User">
New User
</cfmail>

or you could add this in the thankyou.cfm if the insert is done there.

kyle
0
 
lepirtleAuthor Commented:
Wow! That was a quick reply...and much appreciated.

Excuse me for sounding dumb but I "think" that it is posting to itself. I say that because I just did a "find" for currentpage and the only other place it appears is
<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>.

I am anxious to try your suggestion but I am not sure where, in my code, the code:
<cfcookie name="fname" value="#FORM.fname#" expires="never">
<cfmail to="myemail@mydomain.com" from="myemail@mydomain.com" server="mail.mydomain.com" subject="New User">
New User
</cfmail>
should appear. May I place it anywhere above the opening <html> tag or does it need to be placed in a specific area?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
kyle1830Commented:
find the part that does the insert into the database an put it right after the insert

posting your code would make it easier.
0
 
lepirtleAuthor Commented:
Thanks.
I inserted your code, where specified, but when I try to open the page I receive an error page:
Error Diagnostic Information
An error occurred while evaluating the expression:
"#FORM.fname#"
Error near line 215, column 32.
--------------------------------------------------------------------------------
Error resolving parameter FORM.FNAME
The specified form field cannot be found. This problem is very likely due to the fact that you have misspelled the form field name.
The error occurred while processing an element with a general identifier of (CFCOOKIE), occupying document position (215:1) to (215:60).
Date/Time: 03/07/05 12:38:20
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Remote Address: 67.167.246.57
HTTP Referrer: http://www.lepirtle.com/lib/completestreets/projdetpop.cfm?hspot=lak004
Query String: hspot=lak004

And to answer your request about posting the code, it follows. I didn't post it earlier because I thought it took too much space but here it is. This is the same code that produced the error.
<cfparam name="URL.hspot" default="1">
<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "frm_comment">
  <cfquery datasource="lib">
  INSERT INTO tbl_compsts_response (add1, add2, altroutes, city, ckres, currratebike, currratewalk, email, employ, fname, formrecd, hspot, improve, intersect, lackofspace, lname, otherfactorsck, otherfactorstxt, otherplck, otherplacestxt, otherwalkck, otherwalktxt, parks, restaur, school, shop, sidewalks, speed, st, trafficexper, trail, transit, turntraffic, vol, zip) VALUES (
  <cfif IsDefined("FORM.add1") AND #FORM.add1# NEQ "">
    '#FORM.add1#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.add2") AND #FORM.add2# NEQ "">
    '#FORM.add2#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.altroutes") AND #FORM.altroutes# NEQ "">
    '#FORM.altroutes#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.city") AND #FORM.city# NEQ "">
    '#FORM.city#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.ckres")>
    1
      <cfelse>
      0
  </cfif>
  ,
  <cfif IsDefined("FORM.currratebike") AND #FORM.currratebike# NEQ "">
    '#FORM.currratebike#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.currratewalk") AND #FORM.currratewalk# NEQ "">
    '#FORM.currratewalk#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.email") AND #FORM.email# NEQ "">
    '#FORM.email#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.employ")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.fname") AND #FORM.fname# NEQ "">
    '#FORM.fname#'
      <cfelse>
      NULL
  </cfif>
  ,
  NOW()
  ,
  <cfif IsDefined("FORM.hspot") AND #FORM.hspot# NEQ "">
    '#FORM.hspot#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.improve") AND #FORM.improve# NEQ "">
    '#FORM.improve#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.intersect")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.lackofspace")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.lname") AND #FORM.lname# NEQ "">
    '#FORM.lname#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.otherfactorsck")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.otherfactorstxt") AND #FORM.otherfactorstxt# NEQ "">
    '#FORM.otherfactorstxt#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.otherplck") AND #FORM.otherplck# NEQ "">
    '#FORM.otherplck#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.otherplacestxt") AND #FORM.otherplacestxt# NEQ "">
    '#FORM.otherplacestxt#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.otherwalkck")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.otherwalktxt") AND #FORM.otherwalktxt# NEQ "">
    '#FORM.otherwalktxt#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.parks")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.restaur")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.school")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.shop")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.sidewalks")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.speed")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.st") AND #FORM.st# NEQ "">
    '#FORM.st#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.trafficexper") AND #FORM.trafficexper# NEQ "">
    '#FORM.trafficexper#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.trail")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.transit")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.turntraffic")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.vol")>
    Yes
      <cfelse>
      No
  </cfif>
  ,
  <cfif IsDefined("FORM.zip") AND #FORM.zip# NEQ "">
    '#FORM.zip#'
      <cfelse>
      NULL
  </cfif>
  )
  </cfquery>
  <cflocation url="/lib/completestreets/thankyou.cfm?&#CGI.QUERY_STRING#">
</cfif>
<cfcookie name="fname" value="#FORM.fname#" expires="never">
<cfmail to="lep@lepirtle.com" from="lep@lepirtle.com" server="mail.lepirtle.com" subject="New User">
A record has been added.
</cfmail>
<cfquery name="regionandlabel" datasource="lib">
SELECT abbrev_loc, region, label
FROM tbl_compsts
WHERE hspot = '#URL.hspot#'</cfquery>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/libtmplt20031113.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
0
 
kyle1830Commented:
move the cfcookie and cfmail, right before the cflocation tag (2 or 3 lines up)

0
 
rob_lorentzCommented:


cfcookie will not work with the cflocation. the cookie never gets sent to the user.
0
 
kyle1830Commented:
now, post the code for the first name form field
0
 
lepirtleAuthor Commented:
<input name="fname" type="text" id="fname" size="15" maxlength="15"
      <cfif isDefined("Cookie.fname")>
            value="<cfoutput>#Cookie.fname#</cfoutput>"
      </cfif> />
0
 
kyle1830Commented:
looks good.... how does it work?
0
 
lepirtleAuthor Commented:
Amizing. It works great!
The cookie function and email notification both work!
Just one thing though. Since I had to remove the cflocation tag, when a user presses the submit button the thankyou.cfm page no longer opens. Might there be a simple way that I could restore that function?
0
 
kyle1830Commented:
add this after the cfmail
            <script language="JavaScript">
                  {
                  window.location="thankyou.cfm";
                  }
                  //  End -->
            </script>      
0
 
lepirtleAuthor Commented:
May I pass a url paramenter in that javascript?
For example, the privious cflocation tag that I deleted read
<cflocation url="/lib/completestreets/thankyou.cfm?&#CGI.QUERY_STRING#">
to open the new using the URL parameter.
0
 
lepirtleAuthor Commented:
Kyle,
Thanks so very much for your time and expertise: quick, accurate. A great combination.
0
 
kyle1830Commented:
you're welcome...good luck
0
All Courses

From novice to tech pro — start learning today.