Re: Re: Passing an Array in HTML
| From: | Michael Adams | Date: | Tue, 23 Nov 2004 08:47:55 +0000 |
| Subject: | Re: Re: Passing an Array in HTML | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-25029@lists.php.net to get a copy of this message | ||
On Mon, 22 Nov 2004 16:12:37 -0800
"Vail, Warren" <Warren.Vail@schwab.com> wrote:
> Only real array I've ever seen in HTML is one passed to JavaScript.
> Anyone else found another way?
>
> I suppose you could do it as a pull down list (preselecting all
> selections), but risk is your user will screw up the data by clicking
> on the list, but that struck me as kind of hokey (a technical term if
> the highest order ;-).
>
> Warren Vail
>
>
> > -----Original Message-----
> > From: news [mailto:news@sea.gmane.org] On Behalf Of MikeA
> > Sent: Monday, November 22, 2004 4:08 PM
> > To: php-windows@lists.php.net
> > Subject: [PHP-WIN] Re: Passing an Array in HTML
> >
> >
> > So the only way to do it is by separating all of the elements
> > instead of sending it as one big array? Hmmm. There is no
> > better way to pass an array?
> >
> > Thanks.
> >
> > Mike
> >
> >
> > "Vail, Warren" <Warren.Vail@schwab.com> wrote in message
> >
> > news:72138202E59CD6118E960002A52CD9D2178E2BF6@n1025smx.nt.schw
> > ab.com...
> > > You can pass array data by adding it to the form (probably
> > not a good
> > > practice, I would choose sessions to pass the data, but incase you
> > > have
> > some
> > > need that is ok, try the following);
> > >
> > > // To add the data to your form;
> > >
> > > Foreach($data_old as $k => $v) echo "<input type=hidden
> > > name=\"dataold[".$k."]\" value =
> > > \"".$v."\">\n";
> > >
> > > // to get the data returned from the form add the following to the
> > > module specified in the form action field
> > >
> > > $data_old = $_POST["dataold"];
> > >
> > > // $data_old now contains the array contents
> > >
> > > Haven't tried this but I suspect it should work; anyone aware of a
> > > limit
> > on
> > > the number of hidden elements in a form?
> > >
> > > Hope this helps,
> > >
> > > Warren Vail
> > >
> > >
> > > > -----Original Message-----
> > > > From: news [mailto:news@sea.gmane.org] On Behalf Of MikeA
> > > > Sent: Monday, November 22, 2004 3:50 PM
> > > > To: php-windows@lists.php.net
> > > > Subject: [PHP-WIN] Passing an Array in HTML
> > > >
> > > >
> > > > I am reading a file into an array ($data_old =
> > > > file("config.old");) and then processing it as I receive
> > information
> > > > from the user. As we all know, the Internet is
> > stateless, so I need
> > > > to read back in the array after I get my answer.
> > > >
> > > > Array definitions are
> > > >
> > > > $data_old = array();
> > > > $data_new = array();
> > > > $data_count = 0;
> > > >
> > > > The output code is
> > > >
> > > > echo "<P><input type='hidden' name='data_old'
> > > > value='".$data_old."'>"; echo
> > > > "<P><input type='hidden'
> > > > name='data_old' value='".$data_new."'>";
> > > > echo "<P><input
> > > > type='hidden' name='data_count'
> > > > value=".$data_count.">";
> > > >
> > > > and the input code is
> > > >
> > > > $data_old = $_REQUEST['data_old'];
> > > > $data_new = $_REQUEST['data_new'];
> > > > $data_count = $_REQUEST['data_count'];
> > > >
> > > > $data_count is working so I am assuming my problem is the
> > way that I
> > > > am passing the array. How can I pass an array or is it not
> > > > possible? I would think that anything can be passed as
> > it is just
> > > > bits of data (pun intended). So what goes out should come
> > in. But,
> > > > for some reason, that is not happening.
> > > >
> > > > Any help, suggestions, and guidance is appreciated.
> > > >
> > > > Mike
> > > >
> > > > --
> > > > PHP Windows Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit:
> > > > http://www.php.net/unsub.php
> > > >
> > >
> > > --
> > > PHP Windows Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
> > --
> > PHP Windows Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
If you set it up properly it can be echoed into the header as
a javascript array and acted on from there.
Compare -
var foo = new Array(
new Array("data1","data2","data3"),
new Array("data4","data5","data6"),
new Array("data7","data8","data9")
);
bar = foo[2][1];
With -
var foo = new Array(
<?php fm happens here which gets sent as identical to the above?>
);
bar = foo[2][1];
Michael Adams