I know that :)
What I needed is a simple way to output and process a number of very
similar fields. Let's say, you want to ban 10 users from a forum at
once. After you've found these users, you could output this:
<input type="checkbox" name="User[10][IsBanned]" value="banned" />
<input type="checkbox" name="User[20][IsBanned]" value="banned" />
<input type="checkbox" name="User[30][IsBanned]" value="banned" />
etc.
After the form is submitted you could do this in PHP:
while(list($key, $value) = each($_POST['User']))
{
/* $key now holds 10, 20, 30 ..., $val holds the value of the checkbox */
}
Additionally each field is accessible through $_POST['User']['10']['isBanned'].
This is possible because PHP treats incoming fields with names like
User[10][isBanned] as associative arrays.
Unfortunately, in CF I cannot do access a field by writing
form.User['20']['IsBanned']. So I ended up writing my own function
which attempts to emulate this behaviour. I also wondered whether
there already was a function somewhere emulating this behaviour. Alas.
:) :(
On 8/4/06, James Holmes <[EMAIL PROTECTED]> wrote:
> FORM variables are a struct in CF. You can access them like this:
>
> <cfloop collection="#FORM#" item="CurrentFormField">
> <cfoutput>#CurrentFormField# is: #FORM[CurrentFormField]#</cfoutput>
> </cfloop>
>
> You can see how from there you can do processing based on the name of
> the Form field etc. You can also use all of the struct functions on
> the FORM scope like StructFindKey() etc.
>
> On 8/4/06, Dmitrii Dimandt <[EMAIL PROTECTED]> wrote:
> > Coming from PHP I sorely miss the following feature:
> >
> > <input name="Name[0][param]">
> > <input name="Name[0][param2]">
> >
> > <input name="Name[1][param]">
> > <input name="Name[1][param1]">
> >
> > When submitted, form values would be accessible through an array. This
> > was immensely helpful in cases when multiple similar records (a list
> > from a database, for instance) needed to be edited simultaneously.
> > However, CF arrays are not hashes, so this feature is unavailable :(
> >
> > I wonder, if there is a function of sorts that would accept incoming
> > form fields with such names and convert them to a manageable array
> > (I'm just too lazy to write it myself :) )
> >
> > Thank you
> >
> >
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:248785
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4