views:

47

answers:

2

I'm currently working on a project and I just can't seem to get my head around a way to get this to work using Coldfusion on the backend, and I'm hoping to find an expert to help. I'm using the jQuery plugin relCopy to add "Ingredient" fields to my form. (I'd link, but it's only allowing one.) This is the beginning of several problems -

1) I've got checkboxes as part of the "duplicated" form items. They get incremented by id - but if all are not selected, I just get notified of the number of items selected, not which specific records were selected.

2) Once I've got the information submitting - I've got no idea how to write the loop in Coldfusion to go through and get the information submitted into the database.

3) How in the world do I go about editing existing records?!?

If I can get 1 and 2 figured out - I think I can work on #3. You can view an example of what I'm trying to accomplish here http://jquery.previewsite.us

Any help would be greatly appreciated.

+3  A: 

The Form scope in ColdFusion is a structure. That means you can introspect it like any other structure. Try using structKeyList() for example to see all the form keys. You can then work with any form field by using bracket notation, #form[somekey]#. You can also use cfdump on the form to see what was sent.

CF Jedi Master
+2  A: 

From what I've seen of your example, the problem is that the IDs of the form elements are being appended with an incremented number, but the names are not.

This means that if you have 2 ingredients, you're going to get something like:

form.quantity = "1,3"
form.quantityType = "tablespoon,cup"
form.ingredient = "oil, flour"
form.notes = "canola,sifted"
form.isheading = "true,false"

You could try to assume that the orders will always be the same (and they probably will, but that's kinda too much magic for me), and do something where you loop over the length of a field that you know must be filled out. You could make a hidden field or something to be sure, but it would look something like

<cfset ingredients = arrayNew(1)>
<cfloop from="1" to ="#listLen(form.quantity)#" index="i">
  <cfset ingredient = structNew()>
  <cfset ingredient.quantity = listGetAt(form.quantity,i)>
  <cfset ingredient.quantityType = listGetAt(form.quantityType,i)>
  {and so on...}
  <cfset listAppend(ingredients,ingredient)>
</cfloop> 

and end up with an array of ingredients.

What I really would do is get the form names to have an iterative number as well, and then you could gather them up with something like

form["quantity#i#"] - which would give you the value of quantity1, quantity2, etc.
Edward M Smith
Yes, using a counter number is the way to go IMO. With the other method (ie list functions) the code will probably blow up the first time any one of the field values contains a comma ...
Leigh