|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Hello,
I'm currently trying to retrive an array from a form in CFMX, but am having a few problems. My form has 11 fields, all named 'newentry[]'. So once the array in the form is created, the action does the following: Code:
<cfset reginfo = "#form.newentry#(1)">
<cfset error = arrayNew(1)>
<!--- Search for Blank Fields --->
<cfloop index="x" from="1" to="11">
<cfif len(trim(reginfo[x]))>
<cfset reginfo[x] = "#HTMLEditFormat(reginfo[x])#">
<cfset error[x] = "no">
<cfelse>
<cfset error[x] = "yes">
</cfif>
</cfloop>
<cfloop index="x" from="1" to="11">
<cfoutput>#reginfo[x]#<p></cfoutput>
</cfloop>
Now, this SHOULD set the array from the form equal to a new array called "reginfo", and then it should check to see if each one is blank, before formatting it and printing out the final results. But its telling me that form.newentry is a part of some java class, and it wont let me do anything. Is there a special method of formatting arrays from a form that I am unaware of? Thanks! |
|
#2
|
|||
|
|||
|
What exactly are you trying to do? If you have 11 fields all named the same thing, they are not treated as an array on the target page. What I would recommend is naming each field something like "newEntry1", "newEntry2", etc.
|
|
#3
|
|||
|
|||
|
in a form you can name something "variable[]" in order to create an array "$variable". the brackets in the form name signify 0, 1, 2, 3 in order that they appear on the form.
I figured this would be the same for cold fusion since it works perfectly in PHP, but i cant get it to work properly. |
|
#4
|
|||
|
|||
|
In PHP, form elements are treated as an array. In CF, form elements are treated as a structure (key-value pairs). So if you want to have multiple forms named the same thing, like field1, field 2, etc...that's fine. But you reference it on the target page as "form.field1", "form.field2", etc. You can also reference it with this type of syntax to specify the key: form['field1']
hope that helps. |
|
#5
|
|||
|
|||
|
Or if you want all the form fields to be named exactly the same, you will get a list of values!
For example: <input type="checkbox" name="state" value="MD" /> <input type="checkbox" name="state" value="PA" /> <input type="checkbox" name="state" value="NY" /> If a user checked all 3 and submitted the form, form['state'] would be equal to "MD,PA,NY". Not sure if this applies, but it sounds like it may. Mike |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Using Form Arrays in CFMX |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|