Connecting Tech Pros Worldwide Forums | Help | Site Map

can an array be posted?

Westcoast Sheri
Guest
 
Posts: n/a
#1: Jul 17 '05
Can I use a form to post an array? If so, why doesn't my example work

note that register globals is on....

<form method="post" action="page2.php">
<?php
$allVariablesFromPreviousPage = $_POST;
echo '<input type="hidden" value="',$allVariablesFromPreviousPage,'">';
?>
</form>

....page2.php should now have all the $_POST variables from my page1.php
in the new variable "$allVariablesFromPreviousPage"...but it doesn't.


kingofkolt
Guest
 
Posts: n/a
#2: Jul 17 '05

re: can an array be posted?


"Westcoast Sheri" <sheri_deb88@nospamun8nospam.com> wrote in message
news:41368F21.4E9BDACB@nospamun8nospam.com...[color=blue]
> Can I use a form to post an array? If so, why doesn't my example work
>
> note that register globals is on....
>
> <form method="post" action="page2.php">
> <?php
> $allVariablesFromPreviousPage = $_POST;
> echo '<input type="hidden" value="',$allVariablesFromPreviousPage,'">';
> ?>
> </form>
>
> ...page2.php should now have all the $_POST variables from my page1.php
> in the new variable "$allVariablesFromPreviousPage"...but it doesn't.
>[/color]

You could try:

foreach ( $_POST as $postitem ) {
echo '<input type="hidden" name="postitem[]" value="' . $postitem .
'">';
}

Then access the vars from the previous page with
$_POST['postitem']['someitem'].

- JP


steve
Guest
 
Posts: n/a
#3: Jul 17 '05

re: can an array be posted?


"kingofkolt" wrote:[color=blue]
> "Westcoast Sheri" <sheri_deb88@nospamun8nospam.com> wrote in
> message
> news:41368F21.4E9BDACB@nospamun8nospam.com...[color=green]
> > Can I use a form to post an array? If so, why doesn’t my[/color]
> example work[color=green]
> >
> > note that register globals is on....
> >
> > <form method="post" action="page2.php">
> > <?php
> > $allVariablesFromPreviousPage = $_POST;
> > echo ’<input type="hidden"[/color]
> value="’,$allVariablesFromPreviousPage,’">’;[color=green]
> > ?>
> > </form>
> >
> > ...page2.php should now have all the $_POST variables from my[/color]
> page1.php[color=green]
> > in the new variable "$allVariablesFromPreviousPage"...but it[/color]
> doesn’t.[color=green]
> >[/color]
>
> You could try:
>
> foreach ( $_POST as $postitem ) {
> echo ’<input type="hidden" name="postitem[]"
> value="’ . $postitem .
> ’">’;
> }
>
> Then access the vars from the previous page with
> $_POST[’postitem’][’someitem’].
>
> - JP[/color]

another approach is to serialize your array, then do a rawurlencode.
Then post it. To retrieve, do a rawurldecode and then unserialize.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-array-po...ict145660.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=487580
Terence
Guest
 
Posts: n/a
#4: Jul 17 '05

re: can an array be posted?


kingofkolt wrote:
[color=blue]
> "Westcoast Sheri" <sheri_deb88@nospamun8nospam.com> wrote in message
> news:41368F21.4E9BDACB@nospamun8nospam.com...
>[color=green]
>>Can I use a form to post an array? If so, why doesn't my example work
>>
>>note that register globals is on....
>>
>><form method="post" action="page2.php">
>><?php
>>$allVariablesFromPreviousPage = $_POST;
>>echo '<input type="hidden" value="',$allVariablesFromPreviousPage,'">';
>>?>
>></form>
>>
>>...page2.php should now have all the $_POST variables from my page1.php
>>in the new variable "$allVariablesFromPreviousPage"...but it doesn't.
>>[/color]
>
>
> You could try:
>
> foreach ( $_POST as $postitem ) {
> echo '<input type="hidden" name="postitem[]" value="' . $postitem .
> '">';
> }
>
> Then access the vars from the previous page with
> $_POST['postitem']['someitem'].
>[/color]

this won't work because you've lost your hash index (var name).
You would be left with
$_POST['postitem'][0]
$_POST['postitem'][1]
$_POST['postitem'][2]
$_POST['postitem'][...]
etc.

if you wanted to retain the original var name, you could incorporate it
into the input item's name.

foreach ( $_POST as $varname => $postitem ) {
echo '<input type="hidden" name="page1_'
.$varname.'" value="'.$postitem.'">';
}

Then when pulling it out, you could loop through $_POST and strip out
the 'page1_' prefix if you want.

CJ Llewellyn
Guest
 
Posts: n/a
#5: Jul 17 '05

re: can an array be posted?


"Westcoast Sheri" <sheri_deb88@nospamun8nospam.com> wrote in message
news:41368F21.4E9BDACB@nospamun8nospam.com...[color=blue]
> Can I use a form to post an array? If so, why doesn't my example work[/color]

Yes, but you really don't want to do that, why not store the array on the
server, and retrieve it when the client makes the next request?

Welcome to the wonderful world of sessions:-

http://www.phpfreaks.com/tutorials/41/0.php



Varavva Yevgen aka xa4anypu
Guest
 
Posts: n/a
#6: Jul 17 '05

re: can an array be posted?


"Westcoast Sheri" <sheri_deb88@nospamun8nospam.com> ???????/???????? ?
???????? ?????????: news:41368F21.4E9BDACB@nospamun8nospam.com...[color=blue]
> Can I use a form to post an array? If so, why doesn't my example work
>
> note that register globals is on....
>
> <form method="post" action="page2.php">
> <?php
> $allVariablesFromPreviousPage = $_POST;
> echo '<input type="hidden" value="',$allVariablesFromPreviousPage,'">';
> ?>
> </form>
>
> ...page2.php should now have all the $_POST variables from my page1.php
> in the new variable "$allVariablesFromPreviousPage"...but it doesn't.
>[/color]
I think you can use functions compact->serialize and unserialize->extract




Closed Thread