Solved

Preserving data in the form or session

Posted on 2004-04-12
15
236 Views
Last Modified: 2013-12-24
How do i preserve  input data in text box or radio button, or menu,
0
Comment
Question by:asamuel
  • 4
  • 4
  • 3
  • +1
15 Comments
 
LVL 9

Accepted Solution

by:
CFDevHead earned 125 total points
ID: 10808036
Menu Example
Menu page:<br>
<a href="actionPage.cfm?testVar=This is a test">Menu One</a>

menu action page
<cfif IsDefined('url.testVar')>
      <cfset session.testVar=url.testVar>
<cfelse>
      <cfset session.testVar=false>
</cfif>


Input/radio Example

<form action="actionPage" method="post">
<input type="text" name="textOne">
<input type="radio"  name="radioTest" value="yes">
<input type="radio"  name="radioTest" value="no">

</form>

Input/radio action page
<cfif IsDefined('form.textOne')>
      <cfset session.textOne=form.textOne>
      <cfset session.radioTest=form.radioTest>
<cfelse>
      <cfset session.textOne=false>
      <cfset session.radioTest=false>
</cfif>
0
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 125 total points
ID: 10808044
Please see all of the options available at this thread :

http:Q_20946898.html

The choices are hidden variables, appending the form structure, session variables, etc.

The choices are discussed in the listed thread...

Here is another thread I found by doing a search that deals with this issue :

http:Q_10321053.html
0
 

Author Comment

by:asamuel
ID: 10808305
<cfparam name="form.custarget" default="">
<cfset session.hygeReq.custarget="">
<CFIF IsDefined("Form.custarget")>
  <CFSET SESSION.hygeReq.custarget = Form.custarget>
  </cfif>
<cfinput name="custarget" type="text" value="#session.hygeReq.custarget#" size="20" required="no" message="Please enter the Pulse target">

That is what i have so far and still when i submit and go back, i get blank
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10808467
that should work.

My guess is taht if you just add this to the top of the page :

<cfparam name="form.custarget" default="">
<cfoutput>*#form.custarget#*</cfoutput>

That you will see :

**

Which means that form.custarget was not defined and so the default parameter of blank was used.
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 10808907
I'm not sure but I believe the following is what your after.
If not, it would help if you let us know what and where you want preserve data, in what process etc.?

<cfparam name="form.test1" default="">
<cfparam name="form.test2" default="">

<cfif isDefined("form.btnSubmit")>

      <!--- do your error checking here --->
      <!--- if everything is fine than perform whatever action you need to do here, for example; update, insert, delete etc. --->
      <!--- after finished do a cflocation here to another page --->
      <!--- if there was an error then do nothing and the form will be populated again with the values the user entered --->

</cfif>

<cfoutput>

<form method="post" action="">

<input type="text" name="test1" value="#form.test1#">
<input type="text" name="test1" value="#form.test2#">
<input type="submit" name="btnSubmit" value="Submit">

</form>

</cfoutput>

0
 

Author Comment

by:asamuel
ID: 10812514
hi mrichmon,
Still is not working, what do you think the problem is
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 9

Expert Comment

by:CFDevHead
ID: 10813939

the reason your session variable is blank is because you clear it every time you load this page unless you post to this page the session variable gets cleared

Your code which does not work
<cfparam name="form.custarget" default="">
<cfset session.hygeReq.custarget="">
<CFIF IsDefined("Form.custarget")>
  <CFSET SESSION.hygeReq.custarget = Form.custarget>
  </cfif>
<cfinput name="custarget" type="text" value="#session.hygeReq.custarget#" size="20" required="no" message="Please enter the Pulse target">

 My code which does work

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<cfparam name="form.custarget" default="">
<cfparam name="session.hygeReq.custarget" default="">

<CFIF Form.custarget is NOT "">
      <CFSET SESSION.hygeReq.custarget = Form.custarget>
</cfif>
<cfform method="post" action="index.cfm">  
<cfinput name="custarget" type="text" value="#session.hygeReq.custarget#" size="20" required="no" message="Please enter the Pulse target">
<input type="submit" value="Go" />
</cfform>

</body>
</html>

Also make sure have an application page with settings like this

<cfapplication       name='SpiralDev'
      clientmanagement='yes'
      clientstorage='cookie'
      setclientcookies='yes'
      sessionmanagement='yes'
      sessiontimeout='#CreateTimeSpan( 0,0,90,0)#'
      applicationtimeout='#CreateTimeSpan(0,5,30,0)#'>
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10814208
As I tried to show you with my test code and CFDevHead explained, unless you are posting to this page you are clearing your variable.

Did you try running the test code I gave?  If so did you notice ** with no text in between?  That is showing that you are clearing the session variable.

Another wway to see this is to remove the default="" from the cfqueryparam so that it will throw an error if it is not defined.  This is a way to visually see what we are trying to tell you...that you are resetting the variable in the session to blank.
0
 

Author Comment

by:asamuel
ID: 10815348
I know it is frustrating for me and you, I did exactly as you mention in your posting, even i copied so don't get any mistakes,
I am still get blank, the way i have it i have this form it has a lot of input fields, and submit button to another page, and the other page has  lot of input fields, and once click on submit on second page take you again to first page, and when i go back nothing,
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10815629
It is because when you go back you form.custarget is no longer defined (on the 2nd page) and so it gets overwritten with "" because of your cfparam

Did you try CFDevHead's modified code?

0
 

Author Comment

by:asamuel
ID: 10815659
Yes, that is what i used, I used his code,
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 10829411
do you have an application page?
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

11 Experts available now in Live!

Get 1:1 Help Now