[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => theShawn [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 1 [islastshown] => [isfirstshown] => 1 [attachments] => [allattachments] => ) --> [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => Stressed_Simon [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> The invoked cfc page: ===================== [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => BKBK [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 5 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> FORM scope and CFCs? - Coldfusion - Advanced Techniques

FORM scope and CFCs? - Coldfusion - Advanced Techniques

I have a application where users take a 90 question multiple choice test, after each of the 6 pages I want to save their answers to an array for later grading. I'm attempting to create a test.cfc...one of my methods is "setAnswers"...in the setAnswers method I cut some code from my earlier non-CFC code where I loop through the elements in the FORM.FieldNames list. I'm not even sure if its possible, but can I pass the FORM as an object to the method? I'm trying not to cheat and just pull from the FORM scope. Any other ideas on a ...

  1. #1

    Default FORM scope and CFCs?

    I have a application where users take a 90 question multiple choice test, after
    each of the 6 pages I want to save their answers to an array for later grading.
    I'm attempting to create a test.cfc...one of my methods is "setAnswers"...in
    the setAnswers method I cut some code from my earlier non-CFC code where I loop
    through the elements in the FORM.FieldNames list.

    I'm not even sure if its possible, but can I pass the FORM as an object to the
    method? I'm trying not to cheat and just pull from the FORM scope. Any other
    ideas on a good way to get this done in a CFC?


    <cffunction name="setAnswers" output="false"
    returntype="boolean"
    hint="sets answers into THIS.myAnswers array">
    <cfargument name="testForm"
    type="any"
    hint="FORM Scope Object?">
    <cfset answersSet = FALSE>

    <cfloop index="TheField" list="#testForm.FieldNames#">
    <cfif FindNoCase("ANSWER_", TheField) >
    <cfset thisInt = ReplaceNoCase(TheField, "ANSWER_", "")>
    <!--- set some elements --->
    <cfset THIS.myAnswers[thisInt] = #Evaluate(TheField)#>
    <!--- at least one answer found...return true --->
    <cfset answersSet = TRUE>
    </cfif>
    </cfloop>

    <cfreturn answersSet />

    </cffunction>

    theShawn Guest

  2. #2

    Default Re: FORM scope and CFCs?

    I have attached a basic CFC that you can create as an object in the session
    scope. You can then call the AddAnswers() method specifiying the FORM scope as
    the struct you are passing AddAnswers(FORM).

    This is very basic and is only meant as a pointer to the right direction, as
    there is no error checking and it assumes that there are no other FORM
    variables created that are not answers.

    Hope it gets you started though!

    <cfcomponent
    hint="This is an object that holds the quiz answers.">

    <!--- create the array to hold answers --->
    <cfset this.Answers = ArrayNew(1)>

    <!--- AddAnswers Method --->
    <cffunction
    name="AddAnswers"
    access="public"
    output="false"
    hint="This adds the answers to the array.">

    <!--- ThisForm Argument --->
    <cfargument
    name="ThisForm"
    type="struct"
    required="yes"
    hint="This is the form from this page.">

    <!--- loop through the answers --->
    <cfloop collection="#ARGUMENTS.ThisForm#" item="ThisAnswer">
    <!--- do not add field names to array --->
    <cfif ThisAnswer IS NOT "FieldNames">
    <!--- add answer to array --->
    <cfset this.Answers = ArrayAppend(this.Answers,
    ARGUMENTS.ThisForm[ThisAnswer])>
    </cfif>

    </cfloop>
    </cffunction>
    </cfcomponent>

    Stressed_Simon Guest

  3. #3

    Default Re: FORM scope and CFCs?

    Thanks Simon, I didn't know to pass the FORM as a struct, that was the most important part.
    theShawn Guest

  4. #4

    Default Re: FORM scope and CFCs?

    Pretty much every variable in CF is in a struct.

    If you set <cfset myVar = "Simon"> you can also reference it as
    VARIABLES.myVar, so it is in the VARIABLES struct. Likewise with APPLICATION,
    CLIENT, SESSION, SERVER, REQUEST, FORM, URL, SERVER, ATTRIBUTES, ARGUMENTS,
    ThisTag, CALLER, etc are all structs.

    This is very handy to know when you need to manipulate variables dynamically.

    Stressed_Simon Guest

  5. #5

    Default Re: FORM scope and CFCs?

    Here is another cute possibility, requiring just one
    line of code to invoke the CFC.

    The invoking cfm page:
    ======================
    <cfif isDefined("form.fieldName1")>
    <!--- Here, the component is in a file called xyz.cfc, in same folder as the
    invoking page--->
    <cfinvoke component="xy" method="addAnswers" argumentcollection="#Form#"
    returnvariable="answerSet">
    </cfif>

    The invoked cfc page:
    =====================
    <cfcomponent displayname="answerSetter" hint="Contains method for setting
    answers into THIS.myAnswers array">
    <cffunction name="setAnswers" output="No" returntype="boolean" hint="sets
    answers into THIS.myAnswers array">
    <cfset passedForm = structNew()>
    <cfset passedForm =#form#>
    <!---if you know the fieldnames--->
    <cfset fieldValue1 = #passedForm.fieldName1#>
    <cfset fieldValue2 = #passedForm.fieldName2#>
    <!---etc. etc.--->
    <!---if you don't know the fieldnames, get them from this list--->
    <cfset fieldNameList = #passedForm.fieldnames#>
    <!---etc. etc.--->
    <cfreturn answerSet>
    </cffunction>
    </cfcomponent>


    BKBK Guest

  6. #6

    Default Re: FORM scope and CFCs?

    Read: xy.cfc
    BKBK Guest

Similar Threads

  1. Sporadic loss of FORM scope data
    By kriskadela in forum Coldfusion - Getting Started
    Replies: 33
    Last Post: January 5th, 06:51 PM
  2. faking a form scope
    By Ekimov in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: June 7th, 10:27 AM
  3. Form validation using CFCs
    By mate of the state in forum Coldfusion - Advanced Techniques
    Replies: 10
    Last Post: May 24th, 08:42 PM
  4. Array scope and a form
    By arlin411 in forum Macromedia ColdFusion
    Replies: 2
    Last Post: March 2nd, 05:08 PM
  5. Structures from URL and FORM scope
    By Lupus 23 in forum Coldfusion - Advanced Techniques
    Replies: 4
    Last Post: March 2nd, 01:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •