Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing a variable among different templates

Posted on 2003-11-11
8
Medium Priority
?
346 Views
Last Modified: 2013-12-24
Hello!  I need to pass my exam_name from exam_name.cfm to create_exam.cfm and after clicking "Create Next Question" link, exam_name is passed in the same template, create_exam.cfm.  I don't know if using a session variable is a good choice for passing a variable from template to template.  Anyway, the session.ExamName is never passed after I click "Create Next Question" link, and I need help with that.  Please also let me know any better ways to pass exam_name among different templates and good web documents that I can learn about passing variables and setting variables.  
p.s. code like below is to test if the session variable is passed in the if statement:
<CFOUTPUT><H1>#session.ExamName# - session</H1></CFOUTPUT>

Here is my code for create_exam.cfm:
<form name="form1" action="create_exam.cfm" method="post">
<!--- use cfparam tag to define a value if x and exam_name are not defined --->
<cfparam name="url.x" default="">
<cfparam name="url.z" default="">
<cfparam name="form.exam_name" default="">

<CFAPPLICATION NAME="Name"
SESSIONMANAGEMENT="Yes"
SESSIONTIMEOUT="#CreateTimeSpan(0, 1, 20, 0)#">

<CFSET session.ExamName='#form.exam_name#'>
<CFOUTPUT><H1>#session.ExamName# Edit Page - session</H1></CFOUTPUT>

<!--- First let's insert this data into our database for safe keeping and later usage.
        (the data is submitted from exam_name.cfm) --->
<cfif form.exam_name is #session.ExamName#>
<CFOUTPUT><H1>#session.ExamName# - session</H1></CFOUTPUT>
<CFINSERT DATASOURCE="userLogin" TABLENAME="tblExams" FORMFIELDS="exam_name">

<cfelseif url.x is "create_next_question">
<CFOUTPUT><H1>#session.ExamName# - session</H1></CFOUTPUT>
<!---  insert question to db --->              
<cfquery name="qQuestionInsert" datasource="userLogin">
         INSERT INTO tblQuestions(exam_id, q_ans, parent_id, correct)
         VALUES('#tblExams.exam_id#', '#form.question#', '0', 'NO')
</cfquery>
<!---  insert answers to db --->
<cfquery name="qAnswerInsert" datasource="userLogin">
         INSERT INTO tblQuestions(exam_id, q_ans, parent_id, correct)
         VALUES('#tblExams.exam_id#', '#form.q_ans#', '1', #form.chbox#)
</cfquery>

<cfelseif url.z is "finish_create_current_exam">
<CFOUTPUT><H1>#session.ExamName# - session</H1></CFOUTPUT>
<!---  insert question to db --->              
<cfquery name="qQuestionInsert" datasource="userLogin">
         INSERT INTO tblQuestions(exam_id, q_ans, parent_id, correct)
         VALUES('#tblExams.exam_id#', '#form.question#', '0', 'NO')
</cfquery>
<!---  insert answers to db --->
<cfquery name="qAnswerInsert" datasource="userLogin">
         INSERT INTO tblQuestions(exam_id, q_ans, parent_id, correct)
         VALUES('#tblExams.exam_id#', '#form.q_ans#', '1', #form.chbox#)
</cfquery>
</cfif>

<!---  if instructor click "submit" from create_edit_exam page to submit an exam name or
         click "create_next_question" link --->
<cfif form.exam_name is #session.ExamName# OR url.x is "create_next_question">
<CFOUTPUT><H1>#session.ExamName# - session</H1></CFOUTPUT>
<h2>Welcome Instructor</h2>            
<p><h4>Enter Question below</h4>
<input type="text" name="question" value="" size=120>
</p>
<p>Weight <input type="text" name="weight" size="4"></p>
<h4>Input Answers and Check the Right Answers</h4>
<table cellpadding="3" cellspacing="3">
<tr>
      <th>#</th>
      <th>Answer</th>
    <th>Correct Answer</th>
</tr>
<cfoutput>
<cfloop index="i" from="1" to="10" step="1">
<cfset q_ans=i>
<cfset chbox=i>
<tr>
  <td>#i#.</td>
  <td><input type="text" name="q_ans" value="" size=120></td>
  <td><input type="checkbox" name="chbox" value="NO"><br></td>
</tr>
</cfloop>
</cfoutput>
</table>
<p><input type="RESET" VALUE="RESET"></p>&nbsp;
</cfif>
<p><a href="create_exam.cfm?x=#create_next_question#"></a></p>
<p><a href="help.cfm?y=#help#">Help</a></p>
<p><a href="create_exam.cfm?z=#finish_create_current_exam#">Finish Create Current Exam</a></p>
</form>

0
Comment
Question by:yrs7
[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
  • 2
  • 2
8 Comments
 
LVL 10

Expert Comment

by:Mause
ID: 9729057
try this
<a href="#void()" onclick="document.form1.submit();"></a>

this will submit the form and every form value is submitted, now you don't need session variables for this anymore

Mause
0
 
LVL 17

Assisted Solution

by:anandkp
anandkp earned 300 total points
ID: 9729921
I wld use Cookies !

Set :
<CFCOOKIE NAME="my_username"  VALUE="anandkp"><!--- use expires property if required ... read cfdocs for more info abt cookies  --->

Read :
<CFIF IsDefined("Cookie.my_username")>
    <CFOUTPUT>#Cookie.my_username#</CFOUTPUT>
</CFIF>

HTH

K'Rgds
Anand
0
 

Author Comment

by:yrs7
ID: 9745915
Due to sentain if conditions required in my program, I cannot use Mause's code, but thanks anyway.  Could you give me more details to fix my program, anandkp?  Thanks.
Ying
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

Author Comment

by:yrs7
ID: 9746024
What I meant in the last message is I need help to pass parameters in create_exam.cfm page when I click "Create Next Question" link in create_exam.cfm page using cookies.
Please help!
Ying
0
 
LVL 17

Expert Comment

by:anandkp
ID: 9746037
yes - its very easy to implement cookies - ive already given u the example on how to use them - what u need to do is ... save the exam_name in a cookie [when the user logs in or submits a form  -as per ur flow]

once u have the exam name in cookie ... access it anywhere by using the above example & u shld be thru

let me know - incase u need help with code ...
so i can guide u thru with it

K'Rgds
Anand
0
 
LVL 10

Accepted Solution

by:
Mause earned 300 total points
ID: 9746500
Thats an option to use cookies but I don't like them (I always try to avoid them).
So if you want to use session variables I think you should add cfide and cftoken to your link like this

<a href="create_exam.cfm?x=#create_next_question#&#SESSION.URLTOKEN#">

and offcourse all session variables must be set.

Mause
0
 

Author Comment

by:yrs7
ID: 9756735
Hello!  Mause, I would like to learn how to use session variable from you in after I fix this program with Cookie since I already modify my code a couple days ago.  I will try your method later.  I hope you don't mind.   anandkp...I do need your help to guide me through the code.  I don't know how to fix the first and forth if statements.  Also, I still don't really know how to pass the cookie after I click "Create Next Question" link.  The following is the code I need help w/.  

<form name="form1" action="create_exam.cfm" method="post">
<cfparam name="url.x" default="">
<cfparam name="url.z" default="">
<cfparam name="form.exam_name" default="">
<cfset e_name=form.exam_name>

<CFCOOKIE NAME="my_examname"  VALUE="e_name" expires="never">

<CFIF IsDefined("Cookie.my_examname")>
    <CFOUTPUT>#Cookie.my_examname#</CFOUTPUT>
</CFIF>

<CFOUTPUT>
<H1>#form.exam_name# Edit Page - form</H1>
<H1>#Cookie.my_examname# - cookie name</H1>
<H1>#e_name# - cookie value</H1>
</CFOUTPUT>
<!--- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&--->
<!--- First let's insert this data into our database for safe keeping and later usage.
        (the data is submitted from exam_name.cfm) --->
<cfif e_exam is #e_name#>
<CFINSERT DATASOURCE="userLogin" TABLENAME="tblExams" FORMFIELDS="exam_name">
<!--- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&--->
<!--- if instructor click "create_next_question" link --->
<cfelseif url.x is "create_next_question">
<!---  insert question to db --->              
<cfquery name="qQuestionInsert" datasource="userLogin">
         INSERT INTO tblQuestions(exam_id, q_ans, parent_id, correct)
         VALUES('#tblExams.exam_id#', '#form.question#', '0', 'NO')
</cfquery>
<!---  insert answers to db --->
<cfquery name="qAnswerInsert" datasource="userLogin">
         INSERT INTO tblQuestions(exam_id, q_ans, parent_id, correct)
         VALUES('#tblExams.exam_id#', '#form.q_ans#', '1', #form.chbox#)
</cfquery>
<!--- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&--->
<cfelseif url.z is "finish_create_current_exam">
<!---  insert question to db --->              
<cfquery name="qQuestionInsert" datasource="userLogin">
         INSERT INTO tblQuestions(exam_id, q_ans, parent_id, correct)
         VALUES('#tblExams.exam_id#', '#form.question#', '0', 'NO')
</cfquery>
<!---  insert answers to db --->
<cfquery name="qAnswerInsert" datasource="userLogin">
         INSERT INTO tblQuestions(exam_id, q_ans, parent_id, correct)
         VALUES('#tblExams.exam_id#', '#form.q_ans#', '1', #form.chbox#)
</cfquery>
<script>
      alert("Exam is created!");
    self.location="create_edit_exam.cfm";
</script>      
</cfif>
<!--- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& --->
<!---  if instructor click "submit" from create_edit_exam page to submit an exam name or
         click "create_next_question" link --->
<cfif e_exam is #e_name# OR url.x is "create_next_question">
<h2>Welcome Instructor</h2>            
<p><h4>Enter Question below</h4>
<input type="text" name="question" value="" size=120>
</p>
<p>Weight <input type="text" name="weight" size="4"></p>
<h4>Input Answers and Check the Right Answers</h4>
<table cellpadding="3" cellspacing="3">
<tr>
      <th>#</th>
      <th>Answer</th>
    <th>Correct Answer</th>
</tr>
<cfoutput>
<cfloop index="i" from="1" to="10" step="1">
<cfset q_ans=i>
<cfset chbox=i>
<tr>
  <td>#i#.</td>
  <td><input type="text" name="q_ans" value="" size=120></td>
  <td><input type="checkbox" name="chbox" value="NO"><br></td>
</tr>
</cfloop>
</cfoutput>
</table>
<p><input type="RESET" VALUE="RESET"></p>&nbsp;
</cfif>
<p><a href="create_exam.cfm?x=#create_next_question#">Create Next Question</a></p>
<p><a href="help.cfm?y=#help#">Help</a></p>
<p><a href="create_exam.cfm?z=#finish_create_current_exam#">Finish Create Current Exam</a></p>
</form>

Thanks for your help!!
0
 

Author Comment

by:yrs7
ID: 9757509
Hi, my cookie question is solved.  The main reason I couldn't pass the variables I need in my form is b/c of some HTML syntax mistake.  
Ying
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

604 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