Re: [PHP] Complex (or not so) array data form submission?

2011-08-04 Thread Shawn McKenzie
On 08/04/2011 01:56 PM, Andrew Ballard wrote:
> On Thu, Aug 4, 2011 at 2:04 PM, Jamie Krasnoo  wrote:
>> Thanks. I think what I got hung up on was that I was trying this:
>>
>> name="addresses[][id]"
>> name="addresses[][address1]"
>> name="addresses[][address2]"
>> name="addresses[][city]"
>> name="addresses[][state]"
>> name="addresses[][zip]"
>>
>> Which wouldn't have given the end result I sought, I don't think. Clear case
>> of not seeing the forest for the trees.
>>
>> Jamie
> 
> It probably would have worked just fine. Not specifying the numeric
> index means that PHP will depend on the order that the browser sends
> the values, but they are generally sent in the order they appear on
> the form. If the numeric index is important, it's better to provide it
> explicitly.
> 
> Andrew

What Jamie posted is equivalent to this:

name="addresses[0][id]"
name="addresses[1][address1]"
name="addresses[2][address2]"
name="addresses[3][city]"
name="addresses[4][state]"
name="addresses[5][zip]"

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Complex (or not so) array data form submission?

2011-08-04 Thread Andrew Ballard
On Thu, Aug 4, 2011 at 2:04 PM, Jamie Krasnoo  wrote:
> Thanks. I think what I got hung up on was that I was trying this:
>
> name="addresses[][id]"
> name="addresses[][address1]"
> name="addresses[][address2]"
> name="addresses[][city]"
> name="addresses[][state]"
> name="addresses[][zip]"
>
> Which wouldn't have given the end result I sought, I don't think. Clear case
> of not seeing the forest for the trees.
>
> Jamie

It probably would have worked just fine. Not specifying the numeric
index means that PHP will depend on the order that the browser sends
the values, but they are generally sent in the order they appear on
the form. If the numeric index is important, it's better to provide it
explicitly.

Andrew

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



Re: [PHP] Complex (or not so) array data form submission?

2011-08-04 Thread Jamie Krasnoo
Thanks. I think what I got hung up on was that I was trying this:

name="addresses[][id]"
name="addresses[][address1]"
name="addresses[][address2]"
name="addresses[][city]"
name="addresses[][state]"
name="addresses[][zip]"

Which wouldn't have given the end result I sought, I don't think. Clear case
of not seeing the forest for the trees.

Jamie

On Thu, Aug 4, 2011 at 10:31 AM, Andrew Ballard  wrote:

> On Thu, Aug 4, 2011 at 1:18 PM, Jamie Krasnoo  wrote:
> >
> > Hey all,
> >
> > I get the basics of submitting a form and organizing the $_POST data
> within
> > arrays (name[], name[key], etc). But if I wanted to submit something like
> > multiple addresses and have it end up organized in array form like this
> from
> > submission is this possible?
> >
> > $addresses = array(
> >0 => array(
> >'id' => '1',
> >'address1' => '...',
> >'address2' => '...',
> >'city'  => '...',
> >'state'=> '...',
> >'zip'   => '...'
> >),
> >1 => array(
> >'id' => '2',
> >'address1' => '...',
> >'address2' => '...',
> >'city'  => '...',
> >'state'=> '...',
> >'zip'   => '...'
> >)
> > );
> >
> > For some reason I can't seem to come up with the right naming schema in
> > forms in order to get this structure.
> >
> > Jamie
>
> It should be pretty straight foward. Your fields would have name such as
> these:
>
> name="addresses[0][id]"
> name="addresses[0][address1]"
> name="addresses[0][address2]"
> name="addresses[0][city]"
> name="addresses[0][state]"
> name="addresses[0][zip]"
>
> And so on.
>
> Andrew
>


Re: [PHP] Complex (or not so) array data form submission?

2011-08-04 Thread Andrew Ballard
On Thu, Aug 4, 2011 at 1:18 PM, Jamie Krasnoo  wrote:
>
> Hey all,
>
> I get the basics of submitting a form and organizing the $_POST data within
> arrays (name[], name[key], etc). But if I wanted to submit something like
> multiple addresses and have it end up organized in array form like this from
> submission is this possible?
>
> $addresses = array(
>    0 => array(
>        'id'             => '1',
>        'address1' => '...',
>        'address2' => '...',
>        'city'          => '...',
>        'state'        => '...',
>        'zip'           => '...'
>    ),
>    1 => array(
>        'id'             => '2',
>        'address1' => '...',
>        'address2' => '...',
>        'city'          => '...',
>        'state'        => '...',
>        'zip'           => '...'
>    )
> );
>
> For some reason I can't seem to come up with the right naming schema in
> forms in order to get this structure.
>
> Jamie

It should be pretty straight foward. Your fields would have name such as these:

name="addresses[0][id]"
name="addresses[0][address1]"
name="addresses[0][address2]"
name="addresses[0][city]"
name="addresses[0][state]"
name="addresses[0][zip]"

And so on.

Andrew

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