Re: How to handle rows of checkboxes upon form submit?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You will be passing the checkboxes as arrays ...

So you will need to access them that way on the next page

Your post field would look something like  (off the top of my head, so don't
quote me): 

     

Array
(
    [selected_fid] =>
                            [0] => apples
                            [1] => oranges
                            [2] => bananas
) 


This assumes that the user selected all the results.  If for instances they
did not (say they checked apples and bananas), then your post array would
look like :
Array
(
    [selected_fid] =>
                            [0] => apples
                            [1] => bananas
) 


The array will automatically increment starting at zero.  However, you can
prefill the array with specific information, in case you need to know which
boxes where checked and which were not...

<INPUT TYPE="checkbox" ID="checkbox_row_6" NAME="selected_fid[1]"
VALUE="apples"> 

There is no reason to do this with hardcode values, but if you were
accessing information from a database, and dynamically creating a series of
checkboxes, then it would be more useful to preload the array with the id
from the database rather then let it auto increment.

Hope you find this useful.


I would suggest for your reading enjoyment :

http://php.net/array

http://us.php.net/manual/en/reserved.variables.php  // specifically the
section on $_POST



--
Stephen Johnson c | eh
The Lone Coder

http://www.thelonecoder.com
continuing the struggle against bad code

http://www.thumbnailresume.com
--




> From: Rob Gould <gouldimg@xxxxxxx>
> Date: Thu, 06 Dec 2007 22:12:22 -0800
> To: <php-general@xxxxxxxxxxxxx>
> Subject:  How to handle rows of checkboxes upon form submit?
> 
> Let's say I have a PHP script which lists a series of objects for sale at a
> yard sale, each with a checkbox to the left of the name of the item.
> 
> If I wanted to have a submit button, and run through the list of items that
> were checked and act on them, how would I do that?
> 
> To gain some knowledge, I went into phpMyAdmin and looked at their checkboxes,
> and I see their code:
> 
> <input type="checkbox" id="checkbox_row_6" value="apples"
> name="selected_fld[]">
> <input type="checkbox" id="checkbox_row_7" value="oranges"
> name="selected_fld[]">
> <input type="checkbox" id="checkbox_row_8" value="bananas"
> name="selected_fld[]">
> 
> 
> So it looks like they do something with name="select_fld[]", which must be
> part of the secret to making this work.
> 
> Any advice is greatly appreciated.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux