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.NamePortfo lioSubmit" )><!--- 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.D SName#" procedure="sp_NameUserPort folio" 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.D SName#" procedure="sp_GetUserPortf olioByUser ID" 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#Curren tRow#" value="#vch_PortfolioName# " size="20" maxlength="30">
<input type="hidden" name="AccountNr#CurrentRow #" value="#vch_accountnr#">
</tr>
</cfloop></cfoutput>
</ul>
<tr>
<td>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<cfoutput><input type="hidden" name="PortfolioCount" value="#rsUserPortfolio.Re cordCount# "></cfoutp ut>
<input type="Submit" name="NamePortfolioSubmit" class="button" value"submit">
</td>
</tr>
</table>
</form>
Please help me out on this.
thanks
kandura
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.NamePortfo
<cfloop from="1" to="#form.portfolioCount#"
<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.D
<CFPROCPARAM type="In" dbvarname="@UserID" value="#UserID#" cfsqltype="CF_SQL_INTEGER"
<CFPROCPARAM type="In" dbvarname="@CompetitionID"
<CFPROCPARAM type="In" dbvarname="@accountNR" value="#AccountNR#" cfsqltype="CF_SQL_VARCHAR"
<CFPROCPARAM type="In" dbvarname="@PortfolioName"
<CFPROCRESULT NAME="rsUserPortfolio" resultset="1">
</CFSTOREDPROC>
</cfloop>
</cfif>
<CFSTOREDPROC datasource="#Application.D
<CFPROCPARAM type="In" dbvarname="@UserID" value="#UserID#" cfsqltype="CF_SQL_INTEGER"
<CFPROCPARAM type="In" dbvarname="@CompetitionID"
<CFPROCRESULT NAME="rsUserPortfolio" resultset="1">
</CFSTOREDPROC>
<form action="nameportfolio.cfm"
<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#Curren
<input type="hidden" name="AccountNr#CurrentRow
</tr>
</cfloop></cfoutput>
</ul>
<tr>
<td>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<cfoutput><input type="hidden" name="PortfolioCount" value="#rsUserPortfolio.Re
<input type="Submit" name="NamePortfolioSubmit"
</td>
</tr>
</table>
</form>
Please help me out on this.
thanks
kandura
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER