EasyCFM.COM ColdFusion Forums / ASP to CFML / Access variables being sent to cfm

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Access variables being sent to cfm

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

jhanson
12-10-2007 @ 4:22 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 2
Joined: Dec 2007

I am a little out of my comfort zone and I could use some help.

I have a classic ASP application that has worked for a long time, and now I need to convert it to coldfusion.  It is a very simple app, in which a CBT (computer based training developed using ToolBook) module passes 4 variables to an Access database.  The CBT uses an HTTP post method to pass the variables and the ASP page reads the variables with: request.form("xxx")

My questions/problem is:  How do I access the variables being sent to my new coldfusion page?  Or what is the equivalent of: request.form("xxx")

CJ
12-10-2007 @ 6:28 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

sounds like it would just be form.xxx

at the top of the page, try this:

<cfdump var="#form#" />

what you see there is available in the form scope (all variables that can be referenced as form.xxx).

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

Teachers open the door. You enter by yourself.
—Chinese Proverb

jhanson
12-11-2007 @ 1:31 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 2
Joined: Dec 2007

CJ, thanks for responding.  I thought it would be in the form.xxx format, however, it is not working for me, so I assumed I was out to lunch.

I am a novice to ColdFusion (but really like it) and I took a whack at converting this ASP page to CFML.  I would appreciate any advice/feedback of what is wrong with it.

The input to this page is a DHTML CBT (using JavaScript).  The CBT passes 4 variables:
myStatus - which is either "Completed" or "Bookmarked"
crsNbr - which is an alpha-numeric id
pgNbr - page number the student is on when the exit button is pushed
myScore - which is the sum of graded questions in the CBT

These variables are set in the CBT (in ToolBook ActionScript), and then the parameters are sent out
(i.e. Set HTTP Post parameter "myStatus" to "Completed")
using an HTTPpost command that reads:
HTTP Post to: "http://192.168.3.5/etj/HTTPpost.cfm"; store return value in myRtnStaus  

Here is the original ASP page (and below that is my cfml conversion code):
'HTTPpost.asp
<%@ Language=VBScript %>
<!--#include file="includes/lib_dbLocation.asp"-->
<% If session("user") = "guest" Then %>

     <%
     ' Open a database connection to jacETJ.MDB
     Conn.Open
     ' Open courses table to retreive max score
     Set rsCrs = Server.CreateObject("ADODB.Recordset")
     sql = "SELECT courseMaxScore, courseTitle FROM CoursesCBT WHERE courseNBR='" & request.form("crsNbr") & "'"
     rsCrs.Open sql, Conn, 2, 3
     
     maxScore = rsCrs("courseMaxScore")
     dteDateStamp = Now
     
     ' Return a response
     strTemp = "Thank you for taking this course as a guest. Your results were NOT recorded. "
     strTemp = strTemp & " If you had taken this course for credit, your status would have been set to " & request.form("myStatus")
     strTemp = strTemp & " on " & FormatDateTime(dteDateStamp, vbLongDate) & " with a score of " & (request.form("myScore")/maxScore)*100 & "%. "
     response.write(strTemp)
     
     session("gScore") = (request.form("myScore")/maxScore)*100
     session("gDate") = dteDateStamp
     session("gCourse") = rsCrs("courseTitle")

     ' Close the recordset and connection
     rsCrs.Close
     Set rsCrs = Nothing
     Conn.Close
     Set Conn = Nothing
     %>
<% Else %>
<%
If session("credit") Then
     ' Open a database connection to jacETJ.MDB
     Conn.Open
     ' Open courses table to retreive max score
     Set rsCrs = Server.CreateObject("ADODB.Recordset")
     sql = "SELECT courseMaxScore FROM CoursesCBT WHERE courseNBR='" & request.form("crsNbr") & "'"
     rsCrs.Open sql, Conn, 2, 3
     
     maxScore = rsCrs("courseMaxScore")
     
     ' Close the recordset and connection
     rsCrs.Close
     Set rsCrs = Nothing
     
     ' Open a recordset containing the "CourseComplete" table
     Set rs = Server.CreateObject("ADODB.Recordset")
     sql = "SELECT * FROM CourseComplete WHERE courseNBR='" & request.form("crsNbr") & "' AND userNameLogon='" & session("user") & "'"
     rs.Open sql, Conn, 2, 3
     
     If NOT rs.EOF Then
     scoreRaw = rs("scoreTemp") + request.form("myScore")
          If request.form("myStatus") = "Completed" Then
               scoreFinal = scoreRaw
               scorePct = (scoreFinal/maxScore)*100
               scoreTemp = 0
          Else
               scoreFinal = 0
               scorePct = 0
               scoreTemp = scoreRaw
          End If
     Else
     scoreRaw = request.form("myScore")
               If request.form("myStatus") = "Completed" Then
               scoreFinal = scoreRaw
               scorePct = (scoreFinal/maxScore)*100
               scoreTemp = 0
          Else
               scoreTemp = request.form("myScore")
               scoreFinal = 0
               scorePct = 0
          End If
     End If
     
     dteDateStamp = Now
     
     ' Determine if we should add a new item to the database or just update an existing item.
     If rs.EOF Then
          rs.AddNew
     End If
     rs("status") = request.form("myStatus")
     rs("dateCompleted") = dteDateStamp
     rs("userNameLogon") =  session("user")
     rs("courseNBR") = request.form("crsNbr")
     rs("bookmark") = request.form("pgNbr")
     rs("score") = scoreFinal
     rs("scoreTemp") = scoreTemp
     rs("scorePercent") = scorePct
     rs.Update
     
     ' Close the recordset
     rs.Close
     
     sql = "SELECT * FROM Users WHERE userNameLogon = '" & session("user") & "'"
     rs.Open sql, Conn, 2, 3
     
     ' Return a response
     strTemp = "Thank you for taking this course " & rs("userNameFirst") & " " & rs("userNameLast") & ". Your results have"
     strTemp = strTemp & " been recorded as "
     strTemp = strTemp & request.form("myStatus") & " for course """ & request.form("crsNbr") & """"
     strTemp = strTemp & " on " & FormatDateTime(dteDateStamp, vbLongDate) & ". "
     strTemp = strTemp & " This page name is: " & request.form("pgNbr") & "." & " Your score was: " & request.form("myScore")
     response.write(strTemp)
     ' Close the recordset and connection
     rs.Close
     Set rs = Nothing
     Conn.Close
     Set Conn = Nothing
     End If
End If
%>

CFML converted page (HTTPpost.cfm):

<!---Use course number passed from CBT to get max score and title data--->
<cfquery name="crsScore" datasource="jacETJ">
     SELECT courseMaxScore, courseTitle
     FROM CoursesCBT
     WHERE courseNbr='#form.crsNbr#'
</cfquery>

<!---Determine if the user is a guest and what to do with the data.  If guest, store the info in a session variable to be used to print certificate.--->
<cfif Session.user IS "guest">
     <cfset Session.gScore = (form.myScore/crsScore.CourseMaxScore)*100>
     <cfset Session.gDate = Now()>
     <cfset Session.gCourse = crsScore.courseTitle>
     <cfoutput>
          <p>Thank you for taking this course as a guest. Your results were NOT permanently recorded.</p>
          <p>If you had taken this course for credit, your status would have been set to #form.myStatus# on #LSDateFormat(Now())# with a score of #(form.myScore/crsScore.CourseMaxScore)*100#%.</p>
     </cfoutput>
<cfelse>
     <cfif Session.credit IS True>
          <cfquery name="crsComp" datasource="jacETJ">
               SELECT *
               FROM CourseComplete
               WHERE courseNbr='#form.crsNbr#' AND userNameLogon='#Session.user#'
          </cfquery>
               <cfif crsComp.RecordCount GT 0>
                    <cfset scoreRaw=crsComp.scoreTemp + form.myScore>
                         <cfif form.myStatus="Completed">
                              <cfset scoreFinal=scoreRaw>
                              <cfset scorePct=(scoreFinal/crsComp.courseMaxScore)*100>
                              <cfset scoreTemp=0>
                         <cfelse>
                              <cfset scoreFinal=0>
                              <cfset scorePct=0>
                              <cfset scoreTemp=scoreRaw>
                         </cfif>
                    <cfquery datasource="jacETJ">
                         UPDATE CourseComplete
                         SET status='#form.myStatus#'
                                   dateCompleted=#Now()#
                                   userNameLogon='#Session.user#'
                                   courseNbr='#form.crsNbr#'
                                   bookmark='#form.pgNbr#'
                                   score=#scoreFinal#
                                   scoreTemp=#scoreTemp#
                                   scorePercent=#scorePct#
                         WHERE ccID=#crsComp.ccID#
                    </cfquery>
               <cfelse>
                    <cfset scoreRaw=form.myScore>
                         <cfif url.myStatus="Completed">
                              <cfset scoreFinal=scoreRaw>
                              <cfset scorePct=(scoreFinal/crsComp.courseMaxScore)*100>
                              <cfset scoreTemp=0>
                         <cfelse>
                              <cfset scoreTemp=form.myScore>
                              <cfset scoreFinal=0>
                              <cfset scorePct=0>
                         </cfif>
                    <cfquery datasource="jacETJ">
                         INSERT INTO CourseComplete(status,
                                                                                           dateCompleted,
                                                                                           userNameLogon,
                                                                                           courseNbr,
                                                                                           bookmark,
                                                                                           score,
                                                                                           scoreTemp,
                                                                                           scorePercent)
                         VALUES('#form.myStatus#',
                                         #Now()#,
                                         '#Session.user#',
                                         '#form.crsNbr#',
                                         '#form.pgNbr#',
                                         #scoreFinal#,
                                         #scoreTemp#,
                                         #scorePct#)
                    </cfquery>
               </cfif>
          <cfquery name="feedback" datasource="jacETJ">
               SELECT *
               FROM Users
               WHERE userNameLogon='#Session.user#'
          </cfquery>
          <!---Return a response--->
          <cfoutput>
               Thank you for taking this course #feedback.userNameFirst# #feedback.userNameLast#. Your results have been recorded as #feedback.status# for course "#feedback.crsNbr#" on #LSDateTime(feedback.dateCompleted).  This page name is: #feedback.bookmark#. Your score was: #feedback.scorePct#%.
          </cfoutput>
     </cfif>
</cfif>


CJ
12-11-2007 @ 4:00 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

i don't know what's wrong with it because you haven't said what error(s) you're getting.

sorry, but i'm not going to look over 100 +/- lines of code to try and guess what the error is and then debug it.

did you try the <cfdump var="#form#"> that i suggested?  if so, what'd you see?  if not, why not?

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

Teachers open the door. You enter by yourself.
—Chinese Proverb


Website Designed and Developed by Pablo Varando.