problem passing variable between forms.

Ask a Question related to PHP Development, Design and Development.

  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. Similar Questions and Discussions

    1. Passing a variable to asp
      I cannot work out how to get the variable namefirst from flash to the asp I use : ...
    2. Passing a variable
      Hello, I know this is a simple question but I can't continue because of this error. My first program has this line <cflocation...
    3. Parse problem passing a variable through an a href
      This is probably just a silly error, although I can't see it. I'm wanting to pass a variable I've set through an a href. I know the variable...
    4. passing javascript variable into asp variable using vbscript
      The subject pretty much sums up what I need to do. Here is what I have so far, but still can't figure out how to get it working: <script...
    5. Passing URL Variable in PHP
      Scott D wrote: echo '<a href=test.php?varName=', urlencode($headquarters_name), '>', $headquarters_name, '<br></a>'; Then in the target...
  3. #2

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


    ----- Original Message -----
    From: "Angelo Zanetti" <binc2@ctech.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

  4. #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

  5. #4

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

    --- Angelo Zanetti <binc2@ctech.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

  6. #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

Posting Permissions

  • You may not post new threads
  • You may 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