Link to home
Start Free TrialLog in
Avatar of kandura
kandura

asked on

retrieving form fields with dynamic names

hi, this has been driving me really crazy. I'm not sure i haven;t asked this one before, but i'm sure i never got an answer.

i have a form with a number of textfields. The number depends on the recordcount of the query they're generated by. Then when the form is submitted, i want to read the fields in a loop. But i haven't been able to figure out yet how to do this.  

I can't imagine there's not a relatively simple solution for it, so i hope somebody knows it.

This is what i'm trying to do:

<cfif IsDefined("form.NamePortfolioSubmit")><!--- if submitted, save new names --->
     <cfloop from="1" to="#form.portfolioCount#" index="i">
     <cfset PortfolioName = ???? this is where the dynamic form name should come. Something like form.AccountNR#i#>
          <cfset AccountNR = same as above>

<!--- stored proc to update the names --->          
<CFSTOREDPROC datasource="#Application.DSName#" procedure="sp_NameUserPortfolio" returncode="Yes">
          <CFPROCPARAM type="In" dbvarname="@UserID" value="#UserID#" cfsqltype="CF_SQL_INTEGER">
          <CFPROCPARAM type="In" dbvarname="@CompetitionID" value="#CompetitionID#" cfsqltype="CF_SQL_INTEGER">
          <CFPROCPARAM type="In" dbvarname="@accountNR" value="#AccountNR#" cfsqltype="CF_SQL_VARCHAR">
          <CFPROCPARAM type="In" dbvarname="@PortfolioName" value="#PortfolioName#" cfsqltype="CF_SQL_VARCHAR">
          <CFPROCRESULT NAME="rsUserPortfolio" resultset="1">
          </CFSTOREDPROC>
     </cfloop>
</cfif>

<CFSTOREDPROC datasource="#Application.DSName#" procedure="sp_GetUserPortfolioByUserID" returncode="Yes">
<CFPROCPARAM type="In" dbvarname="@UserID" value="#UserID#" cfsqltype="CF_SQL_INTEGER">
<CFPROCPARAM type="In" dbvarname="@CompetitionID" value="#CompetitionID#" cfsqltype="CF_SQL_INTEGER">
<CFPROCRESULT NAME="rsUserPortfolio" resultset="1">
</CFSTOREDPROC>
<form action="nameportfolio.cfm" method="post">
<table width="50%">
     <tr>
          <td>
               AccountNr
          </td>
          <td>
               PortfolioName
          </td>
     </tr>
<ul>
     <cfoutput><cfloop query="rsUserportfolio">
     <tr>
          <td>
               <li>  #vch_AccountNR#
          </td>
          <td>
               <input type="Text" name="PortfolioName#CurrentRow#" value="#vch_PortfolioName#" size="20" maxlength="30">
               <input type="hidden" name="AccountNr#CurrentRow#" value="#vch_accountnr#">
     </tr>
     </cfloop></cfoutput>
</ul>
     <tr>
          <td>
               &nbsp;
          </td>
     </tr>
     <tr>
          <td colspan="2" align="center">
          <cfoutput><input type="hidden" name="PortfolioCount" value="#rsUserPortfolio.RecordCount#"></cfoutput>
               <input type="Submit" name="NamePortfolioSubmit" class="button" value"submit">
          </td>
     </tr>
</table>
</form>

Please help me out on this.

thanks
kandura
ASKER CERTIFIED SOLUTION
Avatar of CF_Spike
CF_Spike

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
Avatar of kandura
kandura

ASKER

perfect! This is exactly what i was looking for. Thank you. (: