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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is wrong with this code 1

Status
Not open for further replies.

offdarock

Programmer
Sep 8, 2003
132
CA
I set my cookies on this page based on feedback form

<cfcookie name="question1" value="#form.question1#">
<cfcookie name="question2" value="#form.question2#">
<cfcookie name="question3" value="#form.question3#">



then on a subsequent page I try to access them

<cfif cookie.question2 is "yes">
<cflocation url="technicalSupport.cfm">
<cfelseif cookie.question3 is "yes">
<cflocation url="storeService.cfm">
<cfelse>
<cflocation url="finish.cfm">
</cfif>



I get this error...

Error resolving parameter COOKIE.QUESTION2


The cookie value QUESTION2 was not found in the current template file. The cause of this error is very likely one of the following things:


The name of the cookie variable has been misspelled.
The cookie variable has not yet been created or has timed out.
 
why are you using cookies to get information from one page to another. you can use the form scope or session variables if you are using them in more than one page.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Cause I am fairly new to cf and that is the only way I know how to do it
 
if you have 3 pages like this

form

action page

page you're using cookies on



if you used <cflocation> after you set your cookes on the action page they will not work. you have to use cfheader instead.

but if you don't need the answers next time they visit the site don't use cookies.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Sounds like you're new. not to worrie. you should see some of my mistakes.

you don't need an action page to create cookies then a 3rd to use them.
just use this on your action page.

Code:
<cfif form.question2 is "yes">
  <cflocation url="technicalSupport.cfm">
<cfelseif form.question3 is "yes">
  <cflocation url="storeService.cfm">
<cfelse>
<cflocation url="finish.cfm">
</cfif>

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
this is what I am trying to do

first page I have 6 questions
the first 3 questions decide what other pages are displayed. it could be all 3 pages displayed or two or just one...
the other 3 questions are just basic info that I want to carry through the other aforementioned pages to the the final action page along with whatever data I collect in those pages and be submitted to a database...

 
The cookie value QUESTION2 was not found in the current template file.

Are you sure the Cookie is being written in the first place? check the Cookies folder after you run the first template where you create the cookies, if they don't show up then that's your problem.

If you want to redirect to some other page then instead of using cookies just save the values in a session variable.

<cfparam name="session.question1" default="#form.question1#">
<cfparam name="session.question2" default="#form.question2#">
<cfparam name="session.question3" default="#form.question3#">


From there just use a conditional.
<cfif session.question1 is "yes">...........


Cookies may not be the best option, users can choose not to accept cookies in which case your whole logic goes to the ground.


grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
LOL...I have done some very nice stuff in CF but sometimes I get stuck on some very small stuff..
 
happens to everybody...





grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
Ok...I must have brain freez here somewhere

I added this to my page
<cfparam name="session.question1" default="#form.question1#">
<cfparam name="session.question2" default="#form.question2#">
<cfparam name="session.question3" default="#form.question3#">



then this
<cfif session.question1 is "yes">
<cflocation url="customerService.cfm">
<cfelseif session.question2 is "yes">
<cflocation url="technicalSupport.cfm">
<cfelseif session.question3 is "yes">
<cflocation url="storeService.cfm">
<cfelse>
<cflocation url="finish.cfm">
</cfif>



but even if question1 is no, I still go to customerservice page....
 
you're using sessions now so you may have a stuck value.
is this the only time you're going to be using those values? if so don't make them sessions.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
keep in mind if you have
Code:
<cfif session.question1 is "yes">
  <cflocation url="customerService.cfm">
<cfelseif session.question2 is "yes">
   <cflocation url="technicalSupport.cfm">
<cfelseif session.question3 is "yes">
   <cflocation url="storeService.cfm">
<cfelse>
<cflocation url="finish.cfm">
</cfif>
on every page you're going to end up on the customer service page all the time. you have to
a) change the value of session.question1
or
2) <-- joke
remove
Code:
<cfif session.question1 is "yes">
  <cflocation url="customerService.cfm">
from your cfif after you've been to the CS page

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
first page I have 6 questions
the first 3 questions decide what other pages are displayed. it could be all 3 pages displayed or two or just one...
the other 3 questions are just basic info that I want to carry through the other aforementioned pages to the the final action page along with whatever data I collect in those pages and be submitted to a database...

Would you post your form?

I'm thinking something like this
Question1 [ no ]
Question2 [ yes ]
Question3 [ yes ]
Question4 [ Somevalue ]
Question5 [ anotherValue ]
Question6 [ OneMoreValue ]

If I set two and three to Yes what you want next is to go to technicalSupport.cfm where you will gather more data. After you are done with that part you want to jump to
storeService.cfm where again you will gather more data.

As a final step you want to dump all the values collected in technicalSUpport.cfm, all the values collected in storeService.cfm and the values for question4,question5 and question6 into a database..


Is this what you are trying to do???




grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
Wow, you explained it better than I could...lol...yes that exactly what Ia m doing
 
and the form you are using to show the 6 initial questions?

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
<form action="basicSurveyProcessor.cfm" method="post" name="continue" enctype="multipart/form-data">
<table width="775" border="0" cellspacing="0" cellpadding="0" align="center">

<tr bgcolor="#CCCCCC">
<td>Question</td>
<td width="62" valign="top">Yes</td>
<td width="58" valign="top">No</td>
</tr>
<tr>
<td>Have you ever called us for customer service?</td>
<td width="62"><input name="question1" type="radio" value="yes"></td>
<td width="58"><input name="question1" type="radio" value="no"></td>
<td rowspan="3">&nbsp;</td>
</tr>
<tr>
<td><span class="style8">Have you ever called us for telephone technical support?</td>
<td width="62"><input name="question2" type="radio" value="yes"></td>
<td width="58"><input name="question2" type="radio" value="no"></td>
</tr>
<tr>
<td><span class="style8">Have you ever visited a MDG store for service?</td>
<td width="62"><input name="question3" type="radio" value="yes"></td>
<td width="58"><input name="question3" type="radio" value="no"></td>
</tr></table>
<p></p>
<table width="775" border="0" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="#CCCCCC">
<td>&nbsp;</td>
<td>Strongly Disagree</td>
<td>Disagree</td>
<td>Somewhat Disagree </td>
<td>Somewhat Agree </td>
<td>Agree</td>
<td>Strongly Agree </td>
<td>No Opinion </td>
</tr>
<tr>
<td>I am satisfied with the quality of my MDG Computer </td>
<td width="60">
<input name="question4" type="radio" value="1">
</td>
<td width="60">
<input name="question4" type="radio" value="2">
</td>
<td width="65">
<input name="question4" type="radio" value="3">
</td>
<td width="65">
<input name="question4" type="radio" value="4">
</td>
<td width="50">
<input name="question4" type="radio" value="5">
</td>
<td width="60">
<input name="question4" type="radio" value="6">
</td>
<td width="60">
<input name="question4" type="radio" value="0">
</td>
</tr>
<tr>
<td>I would recommend MDG to a friend or colleague who is looking to buy a computer </td>
<td width="60">
<input name="question5" type="radio" value="1">
</td>
<td width="60">
<input name="question5" type="radio" value="2">
</td>
<td width="65">
<input name="question5" type="radio" value="3">
</td>
<td width="65">
<input name="question5" type="radio" value="4">
</td>
<td width="50">
<input name="question5" type="radio" value="5">
</td>
<td width="60">
<input name="question5" type="radio" value="6">
</td>
<td width="60">
<input name="question5" type="radio" value="0">
</td>
</tr>
<tr>
<td span>When it comes time for me to purchase a new computer, I will buy an MDG.</td>
<td width="60">
<input name="question6" type="radio" value="1">
</td>
<td width="60">
<input name="question6" type="radio" value="2">
</td>
<td width="65">
<input name="question6" type="radio" value="3">
</td>
<td width="65">
<input name="question6" type="radio" value="4">
</td>
<td width="50">
<input name="question6" type="radio" value="5">
</td>
<td width="60">
<input name="question6" type="radio" value="6">
</td>
<td width="60">
<input name="question6" type="radio" value="0">
</td>
</tr>
<tr>
<td align="right" colspan="8">
<input name="continue" type="submit" value="Continue">
</td>
</tr>
</table>
</form>
 
OK.
I'm going to assume they don't have to answer the three questions if they don't want to, in which case the default value for the answer will be 'NO'.
I'm also assuming that once you submit and get redirected to the next page you are going to resubmit to the basicSurveyProcessor.cfm page to see where to go next.
One more thing, you will have to add a hidden value on your forms so we will know who is the Originator.

In your basicSurveyProcessor.cfm page write the following
Code:
<cfparam name="originator" default="none">


<cfswitch expression="#originator#">
<cfcase value="firstPage">
	<cfparam name="question1" default="no">
	<cfparam name="question2" default="no">
	<cfparam name="question3" default="no">
	<cfparam name="question4" default="">
	<cfparam name="question5" default="">
	<cfparam name="question6" default="">
<!---build the list of pages to jump next.--->
	<cfif question1 is "yes">
	<cfset session.listOfPages=listAppend(session.listOfPages,"customerService.cfm")>
	<cfelseif question2 is "yes">
	<cfset session.listOfPages=listAppend(session.listOfPages,"technicalSupport.cfm")>
	<cfelseif question3 is "yes">
	<cfset session.listOfPages=listAppend(session.listOfPages,"storeService.cfm")>
	<cfelse>
	<cfset session.listOfPages=listAppend(session.listOfPages,"finish.cfm")>
	</cfif>
	<cfset session.question4=question4>
	<cfset session.question5=question5>
	<cfset session.question6=question6>
	
</cfcase>
<cfcase value="custService">
	<cfparam name="yourvarsforCustService" default="yourvalues">
	<!--- More lines like this depending on your form--->
	<cfset session.yourvarsforCustService=yourvarsforCustService>

</cfcase>
<cfcase value="techSupport">
	<cfparam name="yourvarsforTechSupport" default="yourvalues">
	<!--- More lines like this depending on your form--->
	<cfset session.yourvarsforTechSupport=yourvarsforTechSupport>

</cfcase>
<cfcase value="storeService">
	<cfparam name="yourvarsforStoreService" default="yourvalues">
	<!--- More lines like this depending on your form--->
	<cfset session.yourvarsforStoreService=yourvarsforStoreService>
</cfcase>
</cfswitch>

<cfset pageToJump=listFirst(session.listOfPages)> <!---get the first template on the list--->
<cfset session.listOfPages=listRest(session.listOfPages)><!---get rid of the first element and save the rest  --->
<cflocation url="#pageToJump#"> <!---Jump to the following page--->

In your last page, finish.cfm just collect all your variables from the Session scope and dump them in the database.
This is a general and simple example, since I don't know your database or tables I couldn't tell you a way to optimize the code. Hopefully you'll pick up an idea or two from here and you'll make it work.

Good luck.


grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top