Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

[PHP] send an array using post/get

Options
  • 27-08-2009 3:23pm
    #1
    Registered Users 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 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 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 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 Posts: 3,568 ✭✭✭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