Re: Complex (or not so) array data form submission?
| From: | Andrew Ballard | Date: | Thu, 04 Aug 2011 17:31:53 +0000 |
| Subject: | Re: Complex (or not so) array data form submission? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314355@lists.php.net to get a copy of this message | ||
On Thu, Aug 4, 2011 at 1:18 PM, Jamie Krasnoo <jkrasnoo@gmail.com> 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