<cfloop list="form.docs_to_approve" index="doc_id">

should be 

<cfloop list="#form.docs_to_approve#" index="doc_id">

-alex

 -----Original Message-----
From:   Sicular, Alexander  
Sent:   Sunday, December 08, 2002 10:52 AM
To:     CF-Talk
Subject:        RE: Help with CFLOOP on a Form

Lose the cfloop, cfoutput query = is the same thing. Lose the approve / delete 
checkbox. Only have one . if checked than yes(approved). Value of checkbox should be 
doc_id.  Funny thing about a checkbox is that they will not cross over to the action 
page if they are not checked. Also like other form elements of the same name the 
values cross over as a list.

<CFQUERY name="doc_list" DATASOURCE="mydsn">
select doc_id, title from documents
where approved = 'no'
</CFQUERY>

<FORM METHOD="POST" ACTION="approval.cfm">
  <TABLE border="1">
  <TR><TH>Title</TH> <TH>Approve?</TH> </TR>

<!--- define the list --->  
<CFOUTPUT query = "doc_list">
<TR> 
<TD>#title#</TD>
 <TD><INPUT type="checkbox" name="docs_to_approve" value="#doc_id#"></TD>
</TR>
</CFOUTPUT>
</TABLE>

<INPUT type="submit" value="Submit">
</FORM>

------------------- approval.cfm --------------
<cfparam name="form.docs_to_approve" default="">         <-- incase nothing was 
approved
<cfif len(form.docs_to_approve)>                                     <-- check if 
there is something
<cfloop list="form.docs_to_approve" index="doc_id">        <-- if yes, loop over the 
doc_id
 stuff to approve...
  <CFQUERY name="doc_list" DATASOURCE="mydsn">
  update documents
  set approved = 1
  where doc_id = #doc_id#
  </CFQUERY>
</cfloop>
<cfelse>                                                                       <-- if 
no , do something else
 nothing to approve...
</cfif>

good luck,
alex

 -----Original Message-----
From:   Barbara Langston [mailto:[EMAIL PROTECTED]] 
Sent:   Sunday, December 08, 2002 9:53 AM
To:     CF-Talk
Subject:        Help with CFLOOP on a Form

I'm fairly new to Cold Fusion and have a question about using CFLoop and forms.  I'm 
not sure how to build the code for the update.

I have an "approval" form - where I'll list documents, and a manager will decide when 
a document is approved or ready to be deleted from the system.  If a checkbox is not 
selected, the document will remain on the list until the next approval process takes 
place (not every document will have a checkbox selected):

<CFQUERY name="doc_list" DATASOURCE="mydsn">
select doc_id, title from documents
where approved = 'no'
</CFQUERY>

<FORM METHOD="POST" ACTION="approval.cfm">
  <TABLE border="1">
  <TR><TH>Title</TH> <TH>Approved</TH> <TH>Delete</TH> </TR>

<!--- define the list --->  
<CFLOOP index="doc_id"  list="#ValueList(doc_list.doc_id)#">
<CFOUTPUT query = "doc_list" startrow="1" endRow="doc_list.RecordCount">
<TR> 
<TD>#title#</TD>
 <TD><INPUT type="checkbox" name="approved" value="approved"></TD>
 <TD><INPUT type="checkbox" name="delete" value="delete"></TD>
</TR>
</CFOUTPUT>
</CFLOOP>
</TABLE>

<INPUT type="submit" value="Submit">
</FORM>


So, the question is, how do I code the "approval.cfm" so that it loops through the 
records.  If approved is selected, the database is updated to indicate 'yes', if 
delete is selected, the record is deleted.  If nothing is selected, the record remains 
the same.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

Reply via email to