INSERT INTO AMUSER.HD_CATEGORY (CATEGORYID, CATEGORYNAME, SURVEYID) VALUES(#currID#, '#currName#', #SURVEYID#) [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => mxstu [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] => 3 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> Looping over form fields - Coldfusion - Advanced Techniques

Looping over form fields - Coldfusion - Advanced Techniques

I need to do an insert into a DB where I have a collection of form fields. I have a field called CATEGORYNAME, which can have from 1 to ten different values. I have matching hidden ID fields that give each CATEGORYNAME a unique primary field ID. Can someone please show me how to properly loop over the fields and insert them in the DB. The SURVEYID field is a constant it nevery changes. <cfloop list="#form.categoryname#" index="field"> <cfquery datasource="#Application.DSN#"> INSERT INTO AMUSER.HD_CATEGORY (CATEGORYID, CATEGORYNAME, SURVEYID) VALUES(#CATEGORYID#, '#FORM.CATEGORYNAME#', #SURVEYID#) </cfquery> </cfloop>...

  1. #1

    Default Looping over form fields

    I need to do an insert into a DB where I have a collection of form fields. I
    have a field called CATEGORYNAME, which can have from 1 to ten different
    values. I have matching hidden ID fields that give each CATEGORYNAME a unique
    primary field ID.

    Can someone please show me how to properly loop over the fields and insert
    them in the DB. The SURVEYID field is a constant it nevery changes.

    <cfloop list="#form.categoryname#" index="field">
    <cfquery datasource="#Application.DSN#">
    INSERT INTO AMUSER.HD_CATEGORY (CATEGORYID, CATEGORYNAME, SURVEYID)
    VALUES(#CATEGORYID#, '#FORM.CATEGORYNAME#', #SURVEYID#)
    </cfquery>
    </cfloop>

    murpg Guest

  2. #2

    Default Re: Looping over form fields

    Is there knowone who can please help with this?
    murpg Guest

  3. #3

    Default Re: Looping over form fields

    murpg,

    If you must use lists (instead of dynamically named form fields), try the
    attached. Note - It assumes that categoryID is also a "form" field.

    <!--- NOT TESTED --->

    <!--- verify lists contain same number of elements --->
    <cfif listLen(form.CATEGORYID) eq listLen(form.CATEGORYNAME)>
    <cfloop from="1" to="#listlen(form.categoryName)#" index="k">
    <cfset currID = listGetAt(form.CATEGORYID, k)>
    <cfset currName = listGetAt(form.categoryName, k)>
    <!--- should really use cfqueryparam with form values --->
    <cfquery datasource="#Application.DSN#">
    INSERT INTO AMUSER.HD_CATEGORY (CATEGORYID, CATEGORYNAME, SURVEYID)
    VALUES(#currID#, '#currName#', #SURVEYID#)
    </cfquery>
    </cfloop>
    </cfif>

    mxstu Guest

Similar Threads

  1. Looping through only hidden fields
    By timsilva in forum Macromedia ColdFusion
    Replies: 4
    Last Post: April 18th, 03:15 AM
  2. Looping through form fields
    By timsilva in forum Macromedia ColdFusion
    Replies: 1
    Last Post: April 14th, 01:03 PM
  3. Populate form values based on previous same form fields
    By Rizyak in forum PHP Development
    Replies: 2
    Last Post: June 11th, 04:27 PM
  4. Replies: 1
    Last Post: July 22nd, 08:31 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
  •