Use the same loop to declare cfparams for your form fields using the query
results as the default""

Then in all of your form fields, use the form scope for the values

When the user first hits the form, the query populates the form scope. When
the user submits, THEIR information overrides the cfparams and stays in the
form scope

Works every time :-) 
(not to mention... it will get rid of all those <cfif> statements ;-)

..:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com



-----Original Message-----
From: Cameron Johnson [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 07, 2006 4:45 PM
To: CF-Talk
Subject: Looping over dynamic checkboxes

The scenario:
I've got a self-posting form that validates against validateForm.cfm. If
there are errors in the form, I declare an error message variable and put in
some text:

<cfset errorMessage = "There were errors in your submission.">

The purpose:
If there are errors, I want the form to be populated with the form scope,
instead of the query scope, so that the user doesn't have to retype
everything. If there are no errors, use the query results:

<cfif isDefined("errorMessage")>
        <input type="Text" name="userFirstName"
value="#form.userFirstName#">
        <cfelse>
                <input type="Text" name="userFirstName"
value="#queryUser.userFirstName#">
</cfif>

The problem:
I've got a set of dynamic checkboxes from the query "getCheckboxes" with the
input name of "checkboxList". Just like in the code above, I want to check
the checkboxes with the form scope if there are errors. But, of all the ways
I've tried, I can't get the checkboxes to check:

<cfloop query="getCheckboxes">
   <cfset local.currentCheckboxID = getCheckboxes.checkboxID />
      <cfif isDefined("errorMessage")>
         <input name="checkboxList" type="checkbox"
value="#getCheckboxes.checkboxID#"
            <cfloop ???>
               <cfif ??? EQ local.currentCheckboxID> 
                  checked
               </cfif>
            </cfloop>
         >
         <cfelse>
            <input name="checkboxList" type="checkbox"
value="#getCheckbox.checkboxID#"
               <cfloop query="queryUser">
                  <cfif queryUser.checkboxID EQ local.currentCheckboxID> 
                     checked
                  </cfif>
               </cfloop>
            >
   </cfif>
</cfoop>

What should I loop over and what should my comparison value be? I'm out of
ideas.

Thanks for the help.

Cameron



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:231623
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to