Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2002
    Posts
    2

    Unanswered: Passing arrays with HTTP Forms

    ... is this possible ... and how would it be done?
    thanks ^_^

  2. #2
    Join Date
    Dec 2002
    Posts
    65

    Yes It's possible...

    You may want to provide a little more info so that a better example can be tailored to your situation, but let's say you have an array on a page that needs to be submitted to the next one and you are using a hidden form field to do this. You can just use the implode function (http://www.php.net/manual/en/function.implode.php) to convert the array to a character delimted string and pass that in the hidden form field and on the next page just use explode (http://www.php.net/manual/en/function.explode.php) to extract the contents back into an array.

    Also, you may opt to just use a session variable instead of a form field depending on what you are trying to do.

    HTH
    -b

  3. #3
    Join Date
    Sep 2002
    Location
    Kyiv, Ukraine
    Posts
    77
    Hmmm ... Some time ago I've encountered with the following problem: I was needed to generate a page that collects data from the user in variable number of input boxes and then passes all that data to the next page for processing ...

    I could easily do naming of the input boxes on the first page. So ideally it looked like creating an array of input_boxes[] and giving all input boxes on the first page names like input_box[1], input_box[2], input_box[3] and so on. And then easily process all data using this array. But, HTML forms seems to be forbidding passing array data ... Or am I wrong?

    P.S.: I've solved the problem using a loop that automatically creates different names for every input_box on the page: input1, input2, input3 .... But of course if I could use array variable instead that would be much more comfortable with further coding ...
    Last edited by aZa; 01-17-03 at 18:10.
    Yours faithfully,
    Yaroslav Zaremba

  4. #4
    Join Date
    Dec 2002
    Posts
    65
    If you're talking about arrays for form text input fields you may want to look at variable variables http://www.devshed.com/Server_Side/P...Var/page1.html .
    (I'm only available at the email address provided in my profile on weekdays, if you have questions or advice, during off hours use AIM). Also any views I provide here or on my website are mine and not representative of any views of my work, family, friends and sometimes even myself.

    http://www.bcyde.com

  5. #5
    Join Date
    Sep 2002
    Location
    Kyiv, Ukraine
    Posts
    77
    Yep, variable variables is what I used in my solution . But I still dreamed if it could be possible to use something like:

    Code:
    <form action="processing.php">
        <input type="text" name="array[1]">
        <input type="text" name="array[2]">
        ..........
        <input type="submit">
    </form>
    And then accessing data from these field in processing.php like $array[1], $array[2] ... But it's not possible and the only solution is using variable variables for processing all input boxes (naming them input1, input2 ...), right?
    Yours faithfully,
    Yaroslav Zaremba

  6. #6
    Join Date
    Sep 2002
    Location
    Kyiv, Ukraine
    Posts
    77
    Paragraph about "Never-ending variables" looks astonishing!
    Thanks for link, nice article!
    Yours faithfully,
    Yaroslav Zaremba

Posting Permissions

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