Professional Web Applications Themes

problem passing variable between forms. - PHP Development

HI all I have a form in which I have a table with dynamic checkboxes, they are in a checkbox array ( name = chk[]...), I pass this variable to the next page using POST I receive the variable and use it, no problem, but then when I try to pass it to the next form in the URL (using an A HREF: <a href='confirmrequest.php?requested=" . $chk . "'> ) then it doesnt get passed. I have also tried sending it with POST and a submit button On the page that receives the variable (or meant to ) I have ...

  1. #1

    Default problem passing variable between forms.


    HI all

    I have a form in which I have a table with dynamic checkboxes, they are in a
    checkbox array ( name = chk[]...), I pass this variable to the next page
    using POST I receive the variable and use it, no problem, but then when I
    try to pass it to the next form in the URL (using an A HREF:

    <a href='confirmrequest.php?requested=" . $chk . "'> )

    then it doesnt get passed. I have also tried sending it with POST and a
    submit button


    On the page that receives the variable (or meant to ) I have tried this with
    POST:

    $chk_array = $_POST['chk'];


    ================================================== =====
    and this with sending the variable as part of the URL:

    echo("count chk: " . count($requested). "<br>");
    ================================================== =====

    My register_globals is off. I am not sure what Im doing wrong,

    Help would be appreciated

    Thanx In advance

    Angelo
    Angelo Zanetti Guest

  2. #2

    Default Re: [PHP] problem passing variable between forms.


    ----- Original Message -----
    From: "Angelo Zanetti" <binc2ctech.ac.za>
    > I have a form in which I have a table with dynamic checkboxes, they are in
    a
    > checkbox array ( name = chk[]...), I pass this variable to the next page
    > using POST I receive the variable and use it, no problem, but then when I
    > try to pass it to the next form in the URL (using an A HREF:
    >
    > <a href='confirmrequest.php?requested=" . $chk . "'> )
    You need to serialize() the array in order to pass all of it's values.

    $ser = urlencode(serialize($chk));

    $url = "confirmrequest.php?requested=$ser";

    Then on the receiving side...

    $chk = unserialize($_GET['requested']);

    You could also just add it to the session and make it easy...

    $_SESSION['chk'] = $chk;

    and on the receiving page:

    $chk = $_SESSION['chk'];

    ---John Holmes...
    Cpt John W. Holmes Guest

  3. #3

    Default Re: [PHP] problem passing variable between forms.

    > I have a form in which I have a table with dynamic checkboxes, they are in a
    > checkbox array ( name = chk[]...), I pass this variable to the next page
    > using POST I receive the variable and use it, no problem, but then when I
    > try to pass it to the next form in the URL (using an A HREF:
    >
    > <a href='confirmrequest.php?requested=" . $chk . "'> )
    >
    > then it doesnt get passed. I have also tried sending it with POST and a
    > submit button
    Isn't $chk an array? To pass an array in a form, you should serialize it and
    encode it, then after receiving it you decode it and unserialize it:

    $portable_array = base64_encode(serialize($array));

    You can then pass $portable_array as a form hidden input value. To turn it
    back into an array:

    $array = unserialize(base64_decode($portable_array));

    --
    Lowell Allen
    Lowell Allen Guest

  4. #4

    Default Re: [PHP] problem passing variable between forms.

    --- Angelo Zanetti <binc2ctech.ac.za> wrote:
    > I pass this variable to the next page using POST I receive the
    > variable and use it, no problem, but then when I try to pass it
    > to the next form in the URL (using an A HREF:
    >
    > <a href='confirmrequest.php?requested=" . $chk . "'> )
    ....
    > My register_globals is off.
    Read back through your question, and at least one problem should be very clear:

    1. The client sends you data in a POST request.
    2. You have register_globals disabled.
    3. You reference $chk.

    You need to reference this as $_POST['chk']. Read this:

    [url]http://www.php.net/register_globals[/url]

    Also, as others have mentioned, you need to understand how to work with arrays
    a bit more. The manual can be very helpful. Read this:

    [url]http://us2.php.net/array[/url]

    Hope that helps.

    Chris

    =====
    Become a better Web developer with the HTTP Developer's Handbook
    [url]http://httphandbook.org/[/url]
    Chris Shiflett Guest

  5. #5

    Default Re: [PHP] problem passing variable between forms.

    Lowell, thanks so much for this response. I am trying to send information from a database query to a form that a user can email and this worked great!

    Quote Originally Posted by Lowell Allen View Post
    > I have a form in which I have a table with dynamic checkboxes, they are in a

    Isn't $chk an array? To pass an array in a form, you should serialize it and
    encode it, then after receiving it you decode it and unserialize it:

    $portable_array = base64_encode(serialize($array));

    You can then pass $portable_array as a form hidden input value. To turn it
    back into an array:

    $array = unserialize(base64_decode($portable_array));

    --
    Lowell Allen
    Hec3 Guest

Similar Threads

  1. Passing a variable to asp
    By SteveW in forum Macromedia Flash Data Integration
    Replies: 6
    Last Post: April 19th, 08:40 PM
  2. P problem passing a variable through an a href
    By kellypw in forum Macromedia ColdFusion
    Replies: 4
    Last Post: May 10th, 12:18 AM
  3. Passing a variable to a URL
    By Starleys webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: January 21st, 04:02 AM
  4. Replies: 7
    Last Post: July 17th, 04:54 AM
  5. Passing URL Variable in PHP
    By Justin Koivisto in forum PHP Development
    Replies: 0
    Last Post: July 3rd, 07:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139