Solved

Simulate IE BACK Button with Coldfusion

Posted on 2006-11-15
4
754 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
[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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
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…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

724 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