Connecting Tech Pros Worldwide Help | Site Map

can an array be posted?

  #1  
Old July 17th, 2005, 09:26 AM
Westcoast Sheri
Guest
 
Posts: n/a
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.

  #2  
Old July 17th, 2005, 09:26 AM
kingofkolt
Guest
 
Posts: n/a

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


  #3  
Old July 17th, 2005, 09:26 AM
steve
Guest
 
Posts: n/a

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
  #4  
Old July 17th, 2005, 09:26 AM
Terence
Guest
 
Posts: n/a

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.

  #5  
Old July 17th, 2005, 09:27 AM
CJ Llewellyn
Guest
 
Posts: n/a

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



  #6  
Old July 17th, 2005, 09:27 AM
Varavva Yevgen aka xa4anypu
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deserializing an array Wayne Wengert answers 4 November 12th, 2005 04:13 AM
How to create an array of unique random numbers for an online quiz alanbe answers 15 July 23rd, 2005 09:28 PM
Passing an array of chars to a function jr answers 58 July 22nd, 2005 06:36 AM
Re-initialize An Array SamMan answers 6 July 17th, 2005 08:29 AM