Link to home
Start Free TrialLog in
Avatar of Dan Schimo
Dan SchimoFlag for United States of America

asked on

coldfusion grab more the one form field to make an insert

Hello Experts,

I am trying to grab form fields in a action page using CF. There are 4 set of 4  fields each
e.g.  

DBLTECHEXPERTID_1
DBLTECHEXPERTID_2
DBLTECHEXPERTID_3
DBLTECHEXPERTID_4

DBLTECHEXPERTTEXT_1
DBLTECHEXPERTTEXT_2
DBLTECHEXPERTTEXT_3
DBLTECHEXPERTTEXT_4

etc

All these fields should be inserted in to a sql.

DBLTECHEXPERTID_1 and DBLTECHEXPERTTEXT_1 should go in to same row. I tried to do this since there will be only 4 fields but I am not able to get the form field value

<cfloop from="1" to="4" index="t">
					<cfoutput>
					<cfset formDBLTECHEXPERTID = "Form.DBLTECHEXPERTID_#t#">
					<cfset formDBLTECHEXPERTTEXT = "Form.DBLTECHEXPERTTEXT_#t#">
					#formDBLTECHEXPERTID#<br>
					#formDBLTECHEXPERTTEXT#<br>
					#t#<br>
					#OFFICEDBLCONTENTID#
					<cfoutput>#formDBLTECHEXPERTID#</cfoutput>
					<!---  <cfquery name="qInsertOfficeTechnicalExpertise" datasource="#application.dsn#" dbtype="#application.dstype#" >
							Insert into EVS.CONTENT_OFFICE_TECH_EXPERT (DBLCONTENTID, DBLTECHEXPERTID, DBLDOCID, DBLPHOTOID, TXTOFFTECHEXPERTBLURB, DBLDISPLAYORDER) 
							VALUES 
							(#OFFICEDBLCONTENTID#, #formDBLTECHEXPERTID#, '123', '456', #formDBLTECHEXPERTTEXT#, '#t#' )
					 </cfquery>	 --->
					 </cfoutput>
					 <cftransaction action="COMMIT" />
				</cfloop>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America 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
Okay lets explore different ways:

Way 1: [Example code- Source is from google search]

<cfloop list="#form.fieldnames#" index="item"><!--- loop through all the form fields --->
  <cfif find('ticketid_',item)><!--- if the form name contains 'ticketid_'. Use findNoCase if you want to ignore case sensitivity --->
    <cfloop from="1" to="#form[item]#" index="counter"><!--- loop through the number in form.ticketid_ --->
      <cfquery datasource="#dsn#">
      INSERT INTO table (fieldname, fieldValue, TicketNum)
      VALUES (
        <cfqueryparam value="#item#" cfsqltype="cf_sql_varchar">,--fieldName from the form
        <cfqueryparam value="#form[item]#" cfsqltype="cf_sql_varchar">--value of the fieldName in the form
        <cfqueryparam value="#counter#" cfsqltype="cf_sql_integer">--ticket number being inserted
       )
      </cfquery>
    </cfloop>
  </cfif>
</cfloop>

Open in new window


Way 2:

check this question from EE

https://www.experts-exchange.com/questions/28702744/Insert-records-with-coldfusion-from-dynamic-input-fields.html
Avatar of Dan Schimo

ASKER

Thank you Gurupreet for your assistance.