Dynamically Add Rows To a Form??
Posted: Tue Jan 03, 2006 1:50 pm
Hello,
I am working on a form for my Intranet site. The form is to has a section where the user fills in what accessories go with the product being sold. (We sell Photocopiers).
Here is a place for the base model, and cost, then I need to be able to ask how many accessories did you sell with it? then depending on the answer give them that many box's to fill in.
I plan on having the accessories be inserted in to a seperate table, and then associated by ID.
I have done this using Coldfusion for a online music site, I learned from this tutorial http://tutorial362.easycfm.com/ but I cannot find any simular tutorial in PHP.
On my coldfusion site, I have a page that just asks how many tracks (songs on cd) then post to the next page which displays the input boxes. I would like to have some javascript that can do this or just repost to the same form to get the additional inputs.
here is the coldfusion version that I have so that maybe somebody can see the logic of it and convert to PHP
Action Page:
Thanks
I am working on a form for my Intranet site. The form is to has a section where the user fills in what accessories go with the product being sold. (We sell Photocopiers).
Here is a place for the base model, and cost, then I need to be able to ask how many accessories did you sell with it? then depending on the answer give them that many box's to fill in.
I plan on having the accessories be inserted in to a seperate table, and then associated by ID.
I have done this using Coldfusion for a online music site, I learned from this tutorial http://tutorial362.easycfm.com/ but I cannot find any simular tutorial in PHP.
On my coldfusion site, I have a page that just asks how many tracks (songs on cd) then post to the next page which displays the input boxes. I would like to have some javascript that can do this or just repost to the same form to get the additional inputs.
here is the coldfusion version that I have so that maybe somebody can see the logic of it and convert to PHP
Code: Select all
<form action="add_tracks_action.cfm" method="post" enctype="multipart/form-data" name="form2" id="form2">
<!--- Need to know how may form fields to process, also need to pass this onto the action page --->
<input type="hidden" name="numba" value="<cfoutput>#form.numba#</cfoutput>">
<input type="hidden" name="album_id" value="<cfoutput>#form.album_id#</cfoutput>">
<table>
<tr><td>Track Number</td><td>Track Name</td><td>Sample File</td></tr>
<cfoutput>
<cfloop from="1" to="#form.numba#" index="idx">
<tr><td><input type="text" name="track_number#idx#" value="#idx#" size="10"></td><td><input type="text" name="track_name#idx#"></td><td><input type="file" name="track#idx#"></td></tr>
</cfloop>
</table>
</cfoutput>
<input type="submit" name="submit" value="Upload">
</form>Action Page:
Code: Select all
<cfloop from="1" to="#form.numba#" index="idx">
<!--- process each file upload seperately --->
<!--- upload the file(s) --->
<cfset field = "track#idx#">
<cfif (IsDefined("#field#")) AND (#Evaluate("#field#")# neq "")>
<cffile action="UPLOAD" filefield="#field#" destination="D:\Sites\ecsmaine.com\wwwroot\klaritymusic\samples" nameconflict="MAKEUNIQUE">
<!--- insert the record into data base --->
<cfquery name="data" datasource="klaritymusic">
<cfoutput>
insert into tracks (album_id,track_number,track_name,sample)
values (#form.album_id#,#form["track_number" & idx]#,'#form["track_name" & idx]#','#cffile.serverFile#')
</cfoutput>
</cfquery>
<cfelse>
<cfquery name="data" datasource="klaritymusic">
<cfoutput>
insert into tracks (album_id,track_number,track_name)
values (#form.album_id#,#form["track_number" & idx]#,'#form["track_name" & idx]#')
</cfoutput>
</cfquery>
</cfif>
</cfloop>