NYCPHP Meetup

NYPHP.org

[nycphp-talk] How to pass array when click on "submit" ?

Elijah Insua tmpvar at gmail.com
Tue Jan 27 12:24:37 EST 2009


<form method="post" action="some.php">
<input name="data[test][]" value="index 0" />
<input name="data[test][]" value="index 1" />
<input name="data[test][]" value="index 2" />
</form>


when this form is submitted $_POST will contain

$_POST['data']['test'][0] = "index 0"
$_POST['data']['test'][1] = "index 1"
$_POST['data']['test'][2] = "index 2"


I'd suggest messing around with [] in the name attribute and looking at what
you can get out of post with different
combinations.

-- Elijah

On Tue, Jan 27, 2009 at 12:16 PM, chad qian <nynj.tech at hotmail.com> wrote:

>  I am not sure how many "name","position",.."zip".I guess maybe I need
> foreach.How to program foreach here?
>
> Thanks!
>
> chad
>
> > Date: Tue, 27 Jan 2009 11:51:19 -0500
> > From: artur at marnik.net
> > To: talk at lists.nyphp.org
> > Subject: Re: [nycphp-talk] How to pass array when click on "submit" ?
>
> >
> > or you can just use:
> > <input name="name[1]" type="text" />
> > <input name="zip[1]" type="text" />
> > ....
> > <input name="name[2]" type="text" />
> > <input name="zip[2]" type="text" />
> > ....
> > <input name="name[3]" type="text" />
> > <input name="zip[3]" type="text" />
> >
> > then you will get an array after the post
> >
> > Artur
> >
> >
> >
> > David Mintz wrote:
> > >
> > >
> > >
> > >
> > > How to program php script to pass all these above
> > > information?"name","position","city","state" and "zip" are all
> > > array.
> > >
> > > Thanks!
> > >
> > > chad
> > >
> > >
> > >
> > > If city, state etc are all scalars, why do you want an array at all?
> And
> > > if you do want some or all of the form data wrapped into an array, you
> > > might want to use notation like
> > >
> > > <input name="person[name]" type="text" />
> > > <input name="person[zip]" type="text" />
> > >
> > > --
> > > David Mintz
> > > http://davidmintz.org/
> > >
> > > The subtle source is clear and bright
> > > The tributary streams flow through the darkness
> > >
> > >
> > >
> ------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > New York PHP User Group Community Talk Mailing List
> > > http://lists.nyphp.org/mailman/listinfo/talk
> > >
> > > http://www.nyphp.org/show_participation.php
> > _______________________________________________
> > New York PHP User Group Community Talk Mailing List
> > http://lists.nyphp.org/mailman/listinfo/talk
> >
> > http://www.nyphp.org/show_participation.php
>
>
> ------------------------------
> Windows Live™: E-mail. Chat. Share. Get more ways to connect. Check it
> out.<http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_allup_explore_012009>
>
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090127/ca780eb7/attachment.html>


More information about the talk mailing list