?
Solved

Dynamic Form Processing

Posted on 2003-02-26
6
Medium Priority
?
126 Views
Last Modified: 2013-12-24
0
Comment
Question by:jmcarroll
[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
6 Comments
 
LVL 17

Expert Comment

by:anandkp
ID: 8032673
huh ???
0
 

Author Comment

by:jmcarroll
ID: 8034567
I'm not sure how that happened... I posted my question and now I see it reads 'no text'... and I can't edit it.

Here's my question:

I have a form that has a number of checkboxes that are generated dynamically.  I have two problems: how can I 'recall' the values of these checkboxes so that I can check/uncheck them later (the idea of this form is students being assigned to organizations for study, so they might belong to one or more and they may change), but also how do I write the update query in a 'dynamic looping' way given the variable number of checkboxes?

This is what I have so far:

      <cfif IsDefined('form.action')>
            <cfif form.action eq 'add'>
                  <cfif IsDefined("form.org") AND ListLen(form.org) GT 0>
                        <cfloop list="#form.org#" index="i">
                              <cfquery name="addorg" datasource="#DSN#">
                              INSERT INTO org_admin
                              (
                                    users_id,
                                    org_id
                              )
                              VALUES
                              (
                                    #form.users_id#,
                                    '#i#'
                              )
                              </cfquery>
                        </cfloop>
                  </cfif>
            </cfif>
            <cfif form.action eq 'update'>
            </cfif>
      </cfif>

      <!--- GENERIC QUERIES AND VARIABLE SETTING --->

      <cfquery name="list" datasource="#DSN#">
      SELECT       *
      FROM       organizations
      ORDER BY org_abbr
      </cfquery>

      <cfquery name="list_org" datasource="#DSN#">
      SELECT       *
      FROM       org_admin
      WHERE       users_id = #url.id#
      </cfquery>

      <!--- END GENERIC QUERIES AND VARIABLE SETTING --->

      <cfform action="" method="post">
      <table border="0" cellpadding="0" cellspacing="0">
      <tr>
                        <td width="25%">&nbsp;</td>
                        <td colspan="3">
                        <table cellpadding="2" cellspacing="0" width="100%">
                        <tr>
                              <td>Please select the Lung Associations that this user is responsible for:</td>
                        </tr>
                        <tr>
                              <td>
                              <cfoutput>#list_org.org_id#</cfoutput>

                              <CF_Columns Cols="3" Records="#list.RecordCount#">
                  
                              <table border="0" cellpadding="2" cellspacing="0" width="100%">
                              <tr>
                              <!--- Loop through the number of columns desired. --->
                              <cfloop index="LoopCount" from="1" to="3">
                                    <!--- Access the start and end variables created by the custom tag. --->
                                    <cfset #start# = ("start" & #LoopCount#)>
                                    <cfset #end# = ("end" & #LoopCount#)>
                                    <td valign="top">
                                    <cfoutput query="list" startrow="#Evaluate(start)#" maxrows="#Evaluate(end)#">
                                          #list_org.id#
                                          <cfinput type="checkbox" value="#list.id#" name="org" /> #org_abbr#<br>
                                    </cfoutput>
                                    </td>
                              </cfloop>
                              </tr>
                              </table>

                              </td>
                        </tr>
                        </table>
                        <br />
                        </td>
      </tr>
      <tr>
            <td width="25%">&nbsp;</td>
            <td colspan="3">
            <cfoutput><input type="hidden" name="users_id" value="#url.id#"></cfoutput>
            <input type="hidden" name="action" value="add">
            <input type="submit" name="Submit">
            </td>
      </tr>
      </table>
      </cfform>
0
 
LVL 17

Accepted Solution

by:
anandkp earned 300 total points
ID: 8039503
hi replace ur code with this & let me know


<CFIF IsDefined('form.action')>
      <CFIF form.action eq 'add'>
            <CFIF IsDefined("form.org") AND ListLen(form.org) GT 0>
                  <CFQUERY name="addorg" datasource="#DSN#"><!--- on add/edit - delte the previous rec from the table --->
                  Delete org_admin
                where users_id = #form.users_id#                              
            </CFQUERY>
            <CFLOOP index="i" from="1" to="#listlen(org)#>
                        <CFQUERY name="addorg" datasource="#DSN#"><!--- insert the new selection --->
                              INSERT INTO org_admin
                              ( users_id,org_id )
                              VALUES
                    (#form.users_id#,'#listgetat(org,i)#')
                        </CFQUERY>
                  </CFLOOP>
            </CFIF>
      </CFIF>
      <CFIF form.action eq 'update'>
      </CFIF>
</CFIF>

<!--- ========================================================================================================== --->

      <!--- GENERIC QUERIES AND VARIABLE SETTING --->
<CFQUERY name="list" datasource="#DSN#">
      SELECT      *
      FROM      organizations
      ORDER BY org_abbr
</CFQUERY>
<CFQUERY name="list_org" datasource="#DSN#">
      SELECT      *
      FROM      org_admin
      WHERE      users_id = #url.id#
</CFQUERY>

<!--- to show selected checkboxes - read the users already selected values --->
<CFSET userorg = #valuelist(list_org.org_id)#>

<!--- ========================================================================================================== --->
<!--- END GENERIC QUERIES AND VARIABLE SETTING --->
<CFFORM action="" method="post">
<TABLE border="0" cellpadding="0" cellspacing="0">
      <TR>
            <TD width="25%">&nbsp;</TD>
            <TD colspan="3">
            <TABLE cellpadding="2" cellspacing="0" width="100%">
                  <TR>
                        <TD>Please select the Lung Associations that this user is responsible for:</TD>
                  </TR>
                  <TR>
                        <TD>
                        <CFOUTPUT>
                              #list_org.org_id#
                        </CFOUTPUT>
                        <CF_COLUMNS Cols="3" Records="#list.RecordCount#">
                        <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
                              <TR>                                    <!--- Loop through the number of columns desired. --->
                                    <CFLOOP index="LoopCount" from="1" to="3">
                                          <!--- Access the start and end variables created by the custom tag. --->
                                          <CFSET #start# = ("start" & #LoopCount#)>
                                          <CFSET #end# = ("end" & #LoopCount#)>
                                          <TD valign="top">
                                          <CFOUTPUT query="list" startrow="#Evaluate(start)#" maxrows="#Evaluate(end)#">
                                                #list_org.id#
                                                <CFINPUT type="checkbox" value="#list.id#" name="org"/
                                <cfif listfindnocase(userorg,loopcount) neq 0>
                                    checked
                                </CFIF>
                                >
                                #org_abbr#<BR>
                                          </CFOUTPUT>
</TD>
                                    </CFLOOP>
                              </TR>
                        </TABLE></TD>
                  </TR>
            </TABLE><BR/></TD>
      </TR>
      <TR>
            <TD width="25%">&nbsp;</TD>
            <TD colspan="3">
            <CFOUTPUT>
                  <INPUT type="hidden" name="users_id" value="#url.id#">
            </CFOUTPUT>
            <INPUT type="hidden" name="action" value="add">
            <INPUT type="submit" name="Submit"></TD>
      </TR>
</TABLE></CFFORM>

<!--- ========================================================================================================== --->

K'Rgds
Anand
0
 
LVL 4

Expert Comment

by:crosenblum
ID: 8044024
Exactly treating your form elements as a list, gives you much more power and capability.

0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10931177
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation in the Cleanup topic area:

Accept anandkp

Please leave any comments here within the next four days.

mrichmon
EE Cleanup Volunteer
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 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