Solved

Preserving data in the form or session

Posted on 2004-04-12
15
244 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
What You Need to Know when Searching for a Webhost Provider
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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