Solved

Simulate IE BACK Button with Coldfusion

Posted on 2006-11-15
4
710 Views
Last Modified: 2013-12-20
How do I code a template so a person can return to the previous page (a form) and retain all of the variables already entered on the previous page ( a form).  Do I need a "submit" button on the sending page?  

I want to mimic the action of pressing the IE BACK button with a Button embedded on a cold fusion page.
0
Comment
Question by:HarleyK1dd
  • 3
4 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 300 total points
ID: 17951378

 Use javascript on the button..

<input type="button" onclick="javascript:history.back()">

0
 
LVL 39

Expert Comment

by:gdemaria
ID: 17951396

 Here is a better way, this code framework shows you how to submit a form page to itself, process the action and then go to the next URL.  If there are any errors on the page, the processing "drops through" without being redirected and shows the values on the form just as the user entered them, without having been saved..




<!--- this is the primary key for the data on this page, expect it to be passed,
      if it is empty, the page will create a new record ----->
<cfparam name="form.contact_id" default="">  
             
<cfset variables.error = "">  <!---- this variable will hold an error message, if a problem occurs ---->

<cfif IsDefined('form.submit')>  <!-- the page has been submitted, process action --->
  <cftransaction action="BEGIN"> <!--- a transaction ensure everything on page is saved together or rolledback on error ---->
  <cftry>  <!---- catch any errors in the cfcatch below ----->
   <cfloop index="ii" list="lastname,firstname,email">  <!--- validate required fields are not empty --->
     <cfif len(form[ii]) eq 0>
          <cfthrow message="Please supply all required fields">
       </cfif>
   </cfloop>
   <cfinclude template="owner_upd.cfm"> <!--- this file inserts or updates the data --->
   <cftransaction action="COMMIT">
  <cfcatch type="Any"> <!---- catch all errors, whether you cfthrow them or if happens in your sql statements ---->
     <cftransaction action="ROLLBACK">
     <cfset variables.error = cfcatch.message> <!---- set your error flag message variable ---->
  </cfcatch>
  </cftry>
  </cftransaction>
  <cfif len(variables.error) eq 0> <!--- if no error, go to your next page ---->
     <cflocation url="/nextpage.cfm?ID=AddVariablesHere" addtoken="no">
  </cfif>
</cfif>

<cfif len(variables.error) eq 0> <!--- this happens on first opening the file, get data ---->

   <cfquery name="getContact" datasource="#request.datasource#">
     select * from contacts
       where contact_id = #val(form.contact_id)#
   </cfquery>
   <!---- the next line will copy every column from the query into a FORM
          variable.  This will allow you to use the form scope below instead
              of the query name.  In case of an error, this allows your page
              to reload the entered values without saving them ---->
   <cfloop index="ii" list="#getContact.columnList#">
      <cfset form[ii] = getContact[ii][getcontacts.currentRow]>
   </cfloop>
   
</cfif>

<cfif len(variables.error) gt 0> <!--- if an error, show it ---->
  <cfoutput><span style="color:red">#variables.error#</span></cfoutput>
</cfif>
<!--- here is your form to get the data ---->

<cfoutput>
<form method="post">  <!---- No Action in form, page will post to itself ---->

 First Name: <input type="Text" name="firstName" value="#form.firstName#"><br><br>
 
 Last Name: <input type="Text" name="LastName" value="#form.lastName#"><br><br>

 Email: <input type="Text" name="email" value="#form.email#"><br><br>

 <input type="Submit" name="submit" value="Save">

</form>
</cfoutput>
0
 

Author Comment

by:HarleyK1dd
ID: 17954958
gdemaria ... Not sure if my comment has already been added ,,, so I will add it again

Added a few points because you super-fast response really helped.  Also you get extra crecit for the "extra" suggestions.  Thank You.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 17956189

 super, thanks much
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now