?
Solved

Adding multiple actions to a form

Posted on 2005-03-07
15
Medium Priority
?
739 Views
Last Modified: 2013-12-24
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
0
Comment
Question by:lepirtle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
15 Comments
 
LVL 8

Expert Comment

by:kyle1830
ID: 13478129
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
 

Author Comment

by:lepirtle
ID: 13478204
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
 
LVL 8

Expert Comment

by:kyle1830
ID: 13478278
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
The Ideal Solution for Multi-Display Applications

Check out ATEN’s VS1912 12-Port DP Video Wall Media Player at InfoComm 2017. Kerri describes how easy it is to design creative video walls in asymmetric layouts and schedule detailed playlists ahead of time with its advanced scheduling feature.

 

Author Comment

by:lepirtle
ID: 13478415
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
 
LVL 8

Expert Comment

by:kyle1830
ID: 13478472
move the cfcookie and cfmail, right before the cflocation tag (2 or 3 lines up)

0
 
LVL 10

Expert Comment

by:rob_lorentz
ID: 13478526


cfcookie will not work with the cflocation. the cookie never gets sent to the user.
0
 
LVL 8

Expert Comment

by:kyle1830
ID: 13478606
now, post the code for the first name form field
0
 

Author Comment

by:lepirtle
ID: 13478635
<input name="fname" type="text" id="fname" size="15" maxlength="15"
      <cfif isDefined("Cookie.fname")>
            value="<cfoutput>#Cookie.fname#</cfoutput>"
      </cfif> />
0
 
LVL 8

Expert Comment

by:kyle1830
ID: 13478648
looks good.... how does it work?
0
 

Author Comment

by:lepirtle
ID: 13478794
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
 
LVL 8

Expert Comment

by:kyle1830
ID: 13478831
add this after the cfmail
            <script language="JavaScript">
                  {
                  window.location="thankyou.cfm";
                  }
                  //  End -->
            </script>      
0
 

Author Comment

by:lepirtle
ID: 13478943
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
 
LVL 8

Accepted Solution

by:
kyle1830 earned 2000 total points
ID: 13478960
sure
<cfoutput>      
   <script language="JavaScript">
               {
               window.location="thankyou.cfm?&#CGI.QUERY_STRING#";
               }
               //  End -->
          </script>  
</cfoutput>
0
 

Author Comment

by:lepirtle
ID: 13479033
Kyle,
Thanks so very much for your time and expertise: quick, accurate. A great combination.
0
 
LVL 8

Expert Comment

by:kyle1830
ID: 13479083
you're welcome...good luck
0

Featured Post

Optimum High-Definition Video Viewing and Control

The ATEN VM0404HA 4x4 4K HDMI Matrix Switch supports 4K resolutions of UHD (3840 x 2160) and DCI (4096 x 2160) with refresh rates of 30 Hz (4:4:4) and 60 Hz (4:2:0). It is ideal for applications where the routing of 4K digital signals is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question