Solved

Preserving data in the form or session

Posted on 2004-04-12
15
241 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
[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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.

738 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