I have a shopping basket which labels hidden inputs with an id based on a database record. So the input might look like this:
<input type="hidden" name="qty12345678" value="5" />
where "12345678" is the id of a record in the basket.
I'm submitting the form with these inputs using AJAX and sending them to a CFC for processing. I usually pre-define all my form field values inside the CFC like so:
<cfcomponent output="false">
<cfscript>
VARIABLES.Instance.Validation = {
field_A = "pass"
, field_B = "pass"
...
}
<cffunction name="Defaults" access="public" returntype="struct" output="false">
<cfscript>
var formDefaults = {
field_a = ""
, field_b = ""
...
}
</cfcomponent>
My problem is, I don't know how to define dynamic form fields inside this structure. The fields can have any 15-digit ID, so I need some kind of loop to preset the form fields, when I don't know the id and name of the field coming in.
Question:
How can I define form fields which use a dynamic 15-digit ID? If there is a better way to get the information into my CFC, I also wouldn't mind. I do have sellerID, buyerID, item-No and qty as record in my basket table, but when a user orders 10 items, I can't set 10 inputs with name ean/qty/buyer/seller in a form, can I? Nor can I param these values then inside my CFC. I'm lost.