Copy link to clipboard
Copied
Hi,
I am developing a form to report the data in the certain date range provided by the user.
The problem is I have to redirect the page back to original page with the error message "data not found in the date range", if the date range provided doesn't contain any data in the database. I am able to redirect the page to the original page using:
<cfif queryname.RecordCount EQ 0>
<cfset action = "error">
<Cflocation>
</cfif>
And I am using the <cfparam> for setting up an action variable to navigate through the code,
<cfparam name="action" default="">
[using the above <cfparam>, tag at the top of the code and using action EQ "report" and "" for navigation through the code]
But, when I am redirecting to the same page, with action varaible value to error and using cflocation it should forget all the varable values in the new page[as expected], so how can I pass the value of a action varaible in the same page and redirect it to the same page upon meeting certain criteria.
If not clear let me know.
Please help,
Vijayvijay77.
vijayvijay77 wrote:
<cflocation url="page.cfm?set=yes&flag=error">...<cfparam name="set" default="yes">
<cfparam name="flag" default="">And I am using
<cfif action EQ "yes">, kind of cfif to navigate inside the code. Am I doing something wrong here.
You say you got it to work. But you have some dangerous code here (if you have not changed it).
The <cflocation url="page.cfm?set=yes&flag=error"> line is going to generate URL scoped variables when ColdFusion processes the page.cfm file after the browse
...Copy link to clipboard
Copied
i have tried the following options:
1) using cfhttp tag and using the cfhttpparam to pass the values
2) And I cannot use Session varaibles
Thank you.
Vijayvijay77.
Copy link to clipboard
Copied
A) WHY can you not use session variables, this type of use is what they are DESIGNED to do.
B) The <cflocation...> tag is a short cut to having the server send the browser a 30x (usually a 302, IIRC) response. Then the BROWSER makes a request to the new page. So, you intend to pass data through that process and not make use of shared memory on the server (AGAIN this is why SESSSION and other shared scoped exist) then you need to use one of the mechnisms for passing data in requests. I.E. either GET (URL) or POST (FORM) data.
Now the easiest to use with a <cflocation...> tag would be get.
<cflocation url="myNewPage.cfm?aKey=foo&bKey=bar">
Copy link to clipboard
Copied
The client requirement has an implication of not using the Session variables.
I tried using the query string method:
<cflocation url="page.cfm?set=yes&flag=error">
It is just redirecting the page back to original form page without the error message.
Is it because at the top of my code, I have
<cfparam name="set" default="yes">
<cfparam name="flag" default="">
And I am using
<cfif action EQ "yes">, kind of cfif to navigate inside the code. Am I doing something wrong here.
Thanks for your valuable feedback,
Vijayvijay77.
Copy link to clipboard
Copied
vijayvijay77 wrote:
<cflocation url="page.cfm?set=yes&flag=error">...<cfparam name="set" default="yes">
<cfparam name="flag" default="">And I am using
<cfif action EQ "yes">, kind of cfif to navigate inside the code. Am I doing something wrong here.
You say you got it to work. But you have some dangerous code here (if you have not changed it).
The <cflocation url="page.cfm?set=yes&flag=error"> line is going to generate URL scoped variables when ColdFusion processes the page.cfm file after the browser requests it. I.E. url.set and url.flag.
The <cfparam name="set"...> tags are NOT specifying the scope of the variables so they are going to default to the 'variables' scope. Which are the local variables of the processing request. I.E. variables.set and variables.flag.
URL.set and VARIABLES.set ARE NOT the same variables. And confusing this can cause some VERY hard to diagnose code problems.
Copy link to clipboard
Copied
Hi ilssac,
After using the query string, I was using the condition to check for the recordcount to check for empty rows .
I removed that condition as I was checking it before the redirection and also after the redirection. And it works now.
Thanks so much for your valuable suggestions and having pateince with these rookie.Everyday I am learning something new in ColdFusion.
I appreciate your help.
Thanks everyone for the feedback,
Vijayvijay77.
Copy link to clipboard
Copied
Your basic idea is ok, so I think the problem lies with your actual code. Can you share with us the code that does the CFLOCATION back to the form page, and the code on the form page that determines whether an error message needs to be displayed? It would also be useful to tell us just what is not working. Does it fail to give the "you made a mistake" message, do you get a ColdFusion error message, or ...? Once we know that we can try to give you more advice.
Also, you indicated that you had tried CFHTTP tags - yo might want to read up on them in the docs to better understand what they are intended for, because they are not relevant to the problem you have described.
-reed
Copy link to clipboard
Copied
<cfif #FORM.Date1# LTE #FORM.Date2#>
<cfif queryname.RecordCount EQ 0>
<cflocation url="setupReport.cfm?action=yes&flag=error">
<cfelse>
---
---
---
<cfif action EQ "yes" AND falg EQ
The part which is not working is "Displaying the error message in the same page as the original form is"
Thanks for your valuable suggestion,
Vijayvijay77.