Connecting Tech Pros Worldwide Help | Site Map

can an array be posted?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 08:26 AM
Westcoast Sheri
Guest
 
Posts: n/a
Default can an array be posted?

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, 08:26 AM
kingofkolt
Guest
 
Posts: n/a
Default 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, 08:26 AM
steve
Guest
 
Posts: n/a
Default Re: 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, 08:26 AM
Terence
Guest
 
Posts: n/a
Default 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, 08:27 AM
CJ Llewellyn
Guest
 
Posts: n/a
Default 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, 08:27 AM
Varavva Yevgen aka xa4anypu
Guest
 
Posts: n/a
Default 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




 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.