Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving a URL with parameters 1

Status
Not open for further replies.

chlebicki

Technical User
Jul 4, 2006
31
US
Hi,

I am trying to do this. After submitting a form I would like to return to a previous URL that contained URL parameters. What is the best way to do this? Is there a way to save the URL and then recall it later?

Thanks,
Craig
 
Somewhere on the form page insert this line of code
Code:
<cfcookie name="myUrl" VALUE="#cgi.SCRIPT_NAME#?#cgi.query_string#">

the script_name will save the url and query_string will save any parameters.

you can later recall the cookie to redisplay the page. Im not sure if this is the best way to do it but it works well for me.

Craig
 
Craig,

Thanks! I think that did it. I have been looking for this solution for the last week. I am curious...since I am new with Dreamweaver and Coldfusion, what language is that? It's not cfml right?

Thanks again so much!
Craig
 
It is coldfusion

do a search on google or your favorite search engine for cgi variables +coldfusion...there are a bunch of them which will allow you to do different things...

Glad I could help, God knows people on this board has help me alot through the years....


Craig
 
Craig,

Okay, so this is where I am at. I did what you recommended and it is working - sort of.

Upon submitting the form it takes me back to the webpage+parameters that I want to go to, but it doesn't seem to update the table. When I use Coldfusion's built in Update Form Wizard and point the 'After Submitting Webpage' to the webpage without parameters upon submitting, the table is updated.

In other words, when I use the script you recommended, it give me my url parameters back, but doesn't seem to update the table when I submit the form.

~Craig
 
can you post some code so we could take a look...



Craig
 
Craig,

I got it to work. Turns out I needed to insert this into the Form's ACTION:

<cfoutput>#CurrentPage#?#MyUrl#</cfoutput>


Now that you have showed me the "cfcookie" function, I am trying to do something with it. I have a few checkboxes the user can select, and am woundering if selected, can the checkbox's value be stored as a cookie, or multiple cookies?

Thanks so far, you have fixed something I have been trying to work on for a week!

~Craig
 
form page

<input type="checkbox" name="Question1" />
<input type="checkbox" name="Question2" />
<input type="checkbox" name="Question3" />


Action page

<cfparam name="form.Question1" default="0">
<cfparam name="form.Question2" default="0">
<cfparam name="form.Question3" default="0">

Do yor DB insert here or whatever you want to do

<cfoutput>
<cfcookie name="myCookie1" value="#form.Question1#">
<cfcookie name="myCookie2" value="#form.Question2#">
<cfcookie name="myCookie3" value="#form.Question3#">
<cfcookie name="myCookie4" value="#form.Question3#">
</cfoutput>

so yo can store the value to more than one cookie...
you should also use cfparam for you checkboxes..if you going to try to add them to a database or use them for processing...

cause if one is not checked and is not cfparamed, it will generate an error


Craig
 
Craig,

I did copied what you wrote and the good thing is no error messages. But also, nothing is being displayed. These are the same 2 pages that I have been working on from the beginning. Once I submit the form, it updates the database and now (thanks to you) returns to the saved URL via the form's action. However none of the cookie variable's are displaying.

I checked the debugger, and it says for cookies 1-4 all the values are still "0". Meaning the checkbox's values aren't getting sent to the webpage for some reason. Any ideas?

Thanks again,
Craig
 
not sure....maybe if your useing a cflocation tag somewhere and they are clear your cfcookies

post some code and I will look it over..

Craig
 
If you place CFCOOKIE and CFLOCATION on the same action page the cookie will not set. The page actually has to stop processing before the cookie gets recorded.

 
Okay I think you are right...

Last night when I was working on my site I accidentally deleted one of the pages and have spent the last 4 hours remaking it. That's the bad news, the good news is some issues I am having right now are digging up some of the dirt that was in my code.

I think you guys are right and the cflocation is playing havec on the cookies. Of the two pages I am working with now one has a dynamic table generated thru coldfusion's dynamic table wizard, and the other is an update form created thru the wizard as well. I have looked and the update form wizard inserts a cflocation at the top of the page. I think it is being used as part of the action to figure out where to go once the form is submitted.

So right now I am having the same problem I talked about previously, where the URL parameters save, but based on how I fill out the update form wizard - I can either 1)submit the form,utilize the cookie, return to the page with dynamic table, which DOESNT update the table, or 2) submit the form, which stays on the current update form page, but DOES update the table.

Any ideas?
~Craig
 
Try this instead of cflocation

<cfoutput>
<script language="javascript">
document.location.href='#INSERT CFCookie or PAGE name here#';
</script></cfoutput>


try that
 
Craig,

Should I insert this where coldfusion's wizard inserted cflocation? Even though the cfcookie name="MyUrl".... is on one webpage (the dynamic table) and the cflocation is on the other (the update form)?

Thanks,
Craig
 
I dont use any wizards when I program so I cant visualize exactly what is going on.

Try switching all cflocations to the code I gave you...
I hardly use (if ever) cflocation anymore, Its just personal preference...


Craig
 
Craig,

You're good. I got it the update table to update my table and recognize the stored URL cookie by replacing cflocation with the javascript you recommended. Thanks!

Now I am inputting the cfcookie code to diplay the cookie's stored checkbox variable that you wrote. I typed it all in but its still not displaying the cookie. The value for the cookie1 according the debugger is still '0'.

When does the cookie1,2... get the values from the checkboxes? Since cookie1,2,... are only referenced on the dynamic table page (where they are displayed) and not on the page where the checkbox's are located, how/when are the value passed? Do I need to insert the cookies on the form page?

Thanks again for our help,
Craig
 
Craig,

Here is the code for my form update page. I am thinking I need to insert the cookie1,2,... somewhere where so it will retain the check box value so I can display it on another page. What do you think?

Thanks,
Craig

<cfparam name="URL.PAM_ID" default="1">
<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<cfif IsDefined("FORM.MM_UpdateRecord") AND FORM.MM_UpdateRecord EQ "form1">
<cfquery datasource="#Request.DSN#">
UPDATE C:\CFusionMX7\ SET M_0000_AM=
<cfif IsDefined("FORM.M_0000_AM")>
Yes
<cfelse>
No
</cfif>
, M_0100_AM=
<cfif IsDefined("FORM.M_0100_AM")>
Yes
<cfelse>
No
</cfif>
, M_0200_AM=
<cfif IsDefined("FORM.M_0200_AM")>
Yes
<cfelse>
No
</cfif>
, M_0300_AM=
<cfif IsDefined("FORM.M_0300_AM")>
Yes
<cfelse>
No
</cfif>
WHERE PAM_ID=#FORM.PAM_ID#
</cfquery>
<cfoutput>
<script language="javascript">
document.location.href='#MyURL#';
</script></cfoutput>
</cfif>
<cfquery name="rsTime" datasource="#Request.DSN#">
SELECT *
FROM C:\CFusionMX7\WHERE PAM_ID = #URL.PAM_ID#
</cfquery>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="<cfoutput>#CurrentPage#</cfoutput>" method="post" name="Time" id="Time">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">M_0000_AM:</td>
<td><input type="checkbox" name="M_0000_AM" value="0000AM" <cfif (#rsTime.M_0000_AM# EQ true)>@@checked@@</cfif>></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">M_0100_AM:</td>
<td><input type="checkbox" name="M_0100_AM" value="0100AM" <cfif (#rsTime.M_0100_AM# EQ true)>@@checked@@</cfif>></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">M_0200_AM:</td>
<td><input type="checkbox" name="M_0200_AM" value="0200AM" <cfif (#rsTime.M_0200_AM# EQ true)>@@checked@@</cfif>></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">M_0300_AM:</td>
<td><input type="checkbox" name="M_0300_AM" value="0300AM" <cfif (#rsTime.M_0300_AM# EQ true)>@@checked@@</cfif>></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Update record"></td>
</tr>
</table>
<input type="hidden" name="MM_UpdateRecord" value="form1">
<input type="hidden" name="PAM_ID" value="<cfoutput>#rsTime.PAM_ID#</cfoutput>">
</form>
<p>&nbsp;</p>
</body>
</html>
 
Try This
<td><input type="checkbox" name="M_0300_AM" value="0300AM" <cfif #rsTime.M_0300_AM# EQ true>checked</cfif>></td>

If you set the cookies on one page, they will be able to be read on another page unless somewhere along the line you clear them.
 
Craig,

Yeah, I took those out already because I read somewhere those don't really need to be there and should be taken out. Still, the cookie's value is still "0", I am guessing from the <cfparam name="Time.M_0300_AM" default="0"> I set at the top of the page i want to display the cookie on (in a dynamic table).

I any thoughts?
~Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top