Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

[PHP] send an array using post/get

  • 27-08-2009 03:23PM
    #1
    Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭


    eg

    [PHP]<form name="formcoup" action="test.php" method="POST">
    <input type="checkbox" name="coupons[]" value="1" >1<br>
    <input type="checkbox" name="coupons[]" value="2">2<br>
    <input type="checkbox" name="coupons[]" value="3">3<br><br>
    <input type="submit" name="Submit" value="" class="submit" >
    </form>
    <?php
    if (isset($_POST)) {
    $state=$_POST;
    $location = "test2.php?stat=$state";
    header("Location: ".$location);
    }
    ?>


    [/PHP]

    test2.php
    [PHP]
    <?php ob_start();
    $xxx = $_GET;


    print_r($xxx);

    //or tried
    foreach($xxx as $statename)
    {
    echo $statename."<br>";
    }

    ?>[/PHP]

    just passes on string 'Array'
    suggestions?


Comments

  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    i just added a dilemter between values and exploded it in test2,
    if anyone has a better solution shoot

    [PHP]
    <form name="formcoup" action="test.php" method="POST">
    <input type="checkbox" name="coupons[]" value="1" style="width:20px; height:20px;">1<br>
    <input type="checkbox" name="coupons[]" value="2" style="width:20px; height:20px;">2<br>
    <input type="checkbox" name="coupons[]" value="3" style="width:20px; height:20px;">3<br><br>
    <input type="submit" name="Submit" value="" class="submit" >
    </form>
    <?php
    if (isset($_POST)) {
    $state=$_POST;
    foreach ($state as $statename)
    {
    $x = $statename."|";
    $ugh .= $x;
    }


    $location = "test2.php?stat=$ugh";
    header("Location: ".$location);
    }
    ?>[/PHP]


    test2.php

    [PHP]<?php ob_start();
    $xxx = $_GET;

    $xx = explode('|',$xxx);

    foreach($xx as $y)
    {
    echo $y."<Br>";
    }
    ?>[/PHP]


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    What about storing the post dat into SESSION?


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    thanks louie, wanted to avoid sessions...


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    You can avoid the second page and whatever you were going to do there do it on this page while you have the POST data in variables/array.


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    thanks louie, but i need second page , i just try break down bits of code for testing sometimes so i know whats not working properly.


  • Advertisement
  • Registered Users, Registered Users 2, Paid Member Posts: 3,519 ✭✭✭ethernet


    You could serialize() the array and post that to the second page. Did this recently in a script and noticed I had to base64_encode() the serialized array before passing it to the second script and then base64_decode() the unserialized data to use it. It avoids use session data if that's what you want.


Advertisement