. How to manage them ?"/>

Tons of . How to manage them ?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,
I'm working on a form that will be used to manage some values of articles by
lot, I mean changing them on a list before submitting them instead of
changing every article value and submit the form.

How can the form be done and the consequent value readed ?

    <input type="text" name="item1-1" value="value1-1"><input type="text"
name="item1-2" value="value1-2"><input type="text" name="item1-3"
    <input type="text" name="item2-1" value="value2-1"><input type="text"
name="item2-2" value="value2-2"><input type="text" name="item2-3"
    <input type="text" name="item3-1" value="value3-1"><input type="text"
name="item3-2" value="value3-2"><input type="text" name="item3-3"

As you can get, every item has 3 values (that is for simplify the form) that
can be changed or not. How to get the values once the form has been
submitted ?

PS: This list is done dynamically, it may have any number of items and any
number of values per item.

Thanks for all.

Re: Tons of . How to manage them ?

Bob Bedford schreef:
Quoted text here. Click to load it

PHP is able to interpret form elements as (multidimensional) arrays if
you define them in the following manner:

<form ...>
   <input type="text" name="item[0][0]" value="value1-1">
   <input type="text" name="item[0][1]" value="value1-2">
   <!-- etc -->
   <input type="text" name="item[1][0]" value="value2-1">
   <input type="text" name="item[1][1]" value="value2-2">
   <!-- etc -->

then in your php script (presuming post submission):


$items = isset( $_POST[ 'item' ] ) && is_array( $_POST[ 'item' ] ) ?
$_POST[ 'item' ] : array();


Re: Tons of . How to manage them ?

Bob Bedford escribió:
Quoted text here. Click to load it

Form parameters that have a [] in their name are converted into PHP
arrays. So you can do:

<input name="item[1][1]">
<input name="item[1][2]">
<input name="item[2][1]">
<input name="item[2][2]">

And read it from $_POST['item']:

     [item] => Array
             [1] => Array
                     [1] => foo
                     [2] => bar

             [2] => Array
                     [1] => dot
                     [2] => com

-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com

Re: Tons of . How to manage them ?

Thanks a lot to both for the quick answer !


Site Timeline