Link to home
Start Free TrialLog in
Avatar of jmcarroll
jmcarroll

asked on

Dynamic Form Processing

Avatar of anandkp
anandkp
Flag of India image

huh ???
Avatar of jmcarroll
jmcarroll

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of anandkp
anandkp
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Exactly treating your form elements as a list, gives you much more power and capability.

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