Don’t you think it would be easier to just have a multi select or a checkbox
for all the users (all named the same)... select the ones you want and
submit. The form field would have a list of selected users. Then you just
run an update query where userid IN list

If you prefer to loop for no reason then there are ways to do that too :-)

Select your users, output a checkbox for each one (user1, user2, user3,
etc...)

On the action side, use the same query to build params for the checkboxes
(because they don’t exist unless they were selected)

Then use the same query to loop the users and update them according to the
corresponding checkbox

<cfloop query="allusers">
        <cfquery...>
        Update users
        Set something = #val(form['user' & userid]#
        Where userid = userid
        </cfquery>
</cfloop>

....id go with the first method :-)

..:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com

 

 

-----Original Message-----
From: Dmitrii Dimandt [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 04, 2006 9:03 AM
To: CF-Talk
Subject: Re: Form parameters as array

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:248788
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to