It's me again, back with the loops.
Background...
I am trying to build an insert form where the user can specify how many
items (records) they would like to add.
Here's my form page:
<cfparam name="MultiForm" default="FALSE">
<cfparam name="i" default="0">
<cfif MultiForm IS True>
<cfoutput>
<form action="addSite2.cfm" method="post"
name="addSite">
<cfloop from="1" to="#URL.NumForms#"
index="i">
<table width="100%" border="0"
cellspacing="2" cellpadding="5">
<tr>
<td width="24%"
class="copyTeal"><div align="right">Author Name: </div></td>
<td width="76%"><input
name="Website_author#i#" type="text"></td>
</tr>
<tr>
<td valign="top"
class="copyTeal">
<div align="right">Website
link:</div></td>
<td><p>
<input
name="Website_Link#i#" type="text" size="45">
</p>
<p><span
class="tealHeader">Please include the http:// and remember to
verify the link's
accuracy.</span></p>
</td>
</tr>
</table>
</cfloop>
<input name="NumForms" type="hidden"
value="#NumForms#">
<input name="MultiForm" type="hidden"
id="MultiForm" value="TRUE">
<p class="tealHeader">
<input type="submit" value="Continue">
</p>
</form>
</cfoutput>
<cfelse>
<form action="addSite2.cfm" method="post"
name="addSite">
<table width="100%" border="0" cellspacing="2"
cellpadding="5">
<tr>
<td width="24%" class="copyTeal"><div
align="right">Author Name: </div></td>
<td width="76%"><input name="Website_author"
type="text" id="Website_author"></td>
</tr>
<tr>
<td valign="top" class="copyTeal">
<div align="right">Website link:</div></td>
<td><p>
<input name="Website_Link" type="text"
id="Website_Link" size="45">
</p>
<p><span class="tealHeader">Please
include the http:// and remember to
verify the link's
accuracy.</span></p></td>
</tr>
</table>
<p class="tealHeader">
<input name="NumForms" type="hidden"
value="1">
<input name="MultiForm" type="hidden"
id="MultiForm" value="FALSE">
<input type="submit" value="Continue">
</p>
</form>
</cfif>
I am getting the value of NumForms from the links:
If you would like to add multiple sites at once,
Select number of sites to add:~~
<a href="addSite.cfm?MultiForm=TRUE&NumForms=5">5</a>
<a href="addSite.cfm?MultiForm=TRUE&NumForms=10">10</a>
<a href="addSite.cfm?MultiForm=TRUE&NumForms=15">
15</a> ~~
So basically, I am looping NumForms times to output that many inout
boxes. They're being dynamically named by appending the value of the
loop index to their names.
When I get to my action page, this is where I get lost.
<cfif MultiForm IS FALSE>
<cfquery datasource="APOOO" name="InsertFields">
Insert Into Websites
(Website_Author,
Website_Link)
Values ('#form.Website_Author#',
'#form.Website_Link#')
</cfquery>
<cfelse>
<CFLOOP
INDEX="i"
FROM=1
TO=#form.NumForms#>
<CFIF form.FIELD1 NEQ "" AND form.FIELD2
NEQ "">
<CFQUERY
DATASOURCE="APOOO">
<!--- run your insert or
update query here --->
Insert Into Websites
(Website_Author,
Website_Link)
Values ('#form.Field1#',
'#form.Field2#')
</CFQUERY>
<cfelse>
Unsuccessful add. There
was data missing in your form.
<cflocation
addtoken="no" url="addSite.cfm">
</cfif>
</cfloop>
</cfif>
I am checking to see whether they are submitting a multiform (true) or
not (false).
If they are not, I go ahead with a normal insert and everything is
peachy.
However, if they are submitting a "multiForm", this is where it gets
sticky. I know I need to loop through the form fields that were
submitted.
<CFLOOP
INDEX="i"
FROM=1
TO=#form.NumForms#>
I want to make sure they arent saying they want to add 5 records and
only add fill out the info for 3, so I add this conditional logic...
<CFIF form.?? NEQ "" AND form.?? NEQ "">
... however, how do I reference the dynamic form elements?? ANd then
when I am ready to run the insert, how do I refererence the values that
were entered into he dynamically-named elements??
<CFQUERY DATASOURCE="APOOO">
<!--- run your insert or
update query here --->
Insert Into Websites
(Website_Author,
Website_Link)
Values ('#form.??#',
'#form.??#')
</CFQUERY>
And then, how do I reference these values once again when confirming the
insert was successful??
<cfif MultiForm IS FALSE>
<cfoutput> <h1><a href="#form.Website_Link#"
target="_blank">#Form.Website_Author#</a> </h1></cfoutput>
<cfelse>
<cfloop from="1" to="#form.NumForms#" index="i">
<cfif #??# NEQ "" AND #??# NEQ "">
<cfoutput>
<h1><a
href="#form.??#" target="_blank">#form.??#</a>
</h1>
</cfoutput>
</cfif>
</cfloop>
</cfif>
I am at a loss here and my brain could implode. I promise if you all
help me with referencing this, I will post a tutorial on this or submit
an article to Fusion Authority on how to do this.
Much obliged :)
Candace K. Cottrell, Web Developer
The Children's Medical Center
One Children's Plaza
Dayton, OH 45404
937-641-4293
http://www.childrensdayton.org
[EMAIL PROTECTED]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4