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

Online survey/questionnaire 1

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
I am trying to write an online questionnaire. There are about 80 questions, and each one has three parts to the response. There is a Yes/No answer, a rating of 1 thur 5, and a comment section. My goal is to present the questions one at a time and have the user "Submit" the responses each time. In other words, I want the responses to each question posted to the database one question at a time. I think the database would be a monster, otherwise.

My problem is, that when I submit the responses to the first question, it clears all my variables, so I am not sure what to use for a counter. Variables that were defined the first time through are no longer defined when I come back to the question page template.

Any suggestions or guidance greatly appreciated.
 
I am pretty new at CF, but have you looked at Session Variables. Their life is the life of the session.

Kathryn


 
Hey Calista,

Can you be more specific about the clearing of the variables? I'm not sure if you mean the responses to the questions, some type of counter that keeps track of where you are, etc.. gets cleared on the next page.

In a general sense though, you can keep variables defined throughout the questionaire by passing them through form or url variables. If you have a counter called "x" that keeps track of the question number, you could create a hidden input variable on the first form like this

<cfoutput><input type=&quot;hidden&quot; name=&quot;x&quot; value=&quot;#x#&quot;></cfoutput>

On the next page, just use the same code in any of your forms or append it onto any links like this
<cfoutput><a href=&quot;page1.cfm?x=#x#&quot;>Next Page</a></cfoutput>

This way, &quot;x&quot; will be available on each page as they move through the questions. You just have to make sure every page passes all variables onto the next page using these techniques. You could also use session or client variables to do the same thing as Kathryn suggested but they introduce other issues although they're easier to implement within the pages.

Let me know if I'm missing the point,
GJ
 
Thanks for the input! I thought about the URL variables, but as far as I know, they only work within the context of a link. I actually tried something similar to what you suggested and I can navigate through the questions via forward and backwards links.

I'll try to explain in greater detail what is happening.
1) I present the first question.
2) I fill in the responses.
3) I hit the &quot;Submit&quot; button.
4) The responses are correctly posted to the database.
5) It returns the first question with an empty form(no responses filled in.)

While trying to debug this thing, I determined that when the question form template is called again, all the variable are cleared. Variables I declared the first time through no longer exist and their values are lost. It acts like it is always the first time through. I tried embedding the &quot;Submit&quot; botton in a link, and that didn't seem to work, but maybe I just wasn't doing it correctly.

I hope I explained myself a little better. Obviously, I'm a newbie, so I appreciate the help.
 
If page 1 contains the form and page 2 receives the responses, does page 2 redirect back to page 1 or does page 2 include page 1 with a <cfinclude>? Just remember that variables you create in a script exist only while the script is executing. If the same script runs again, they are re-created as if they never existed. This is why you have to pass them via form and url variables to keep their values across pages.

GJ
 
I have 2 pages, the form page, which presents the question, and a page to process the question, and on the processing page, I am using <CFLOCATION> to redirect back to the form page. I'll see what I can do with the hidden variables you mentioned earlier. Thanks! :)
 
Thanks GunJack, I've got it now using URL variables *:->*. Now, back to one of my original problems with this silly thing, but I'll make a new thread for it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top