sending array with POST from a hidden input form field?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pablo

    sending array with POST from a hidden input form field?

    Dear News Groupers,

    I'am trying to send a php array with a hidden input field from a form to
    another script.
    The array is NOT made directly by way of <input name="arrayname[]" />.

    The array is made by normal php code and then
    submitted between form-tags as
    echo "<input type='hidden' name=\"arraynam e\" value=\"$arrayn ame\" />" ;

    I can see that the receiving script receives the array but it counts only 1
    item and not the presumed amount.

    Can this be done?
    And how should it be done then?

    TIA,

    pablo



  • oeb -=- bleh bleh bleh

    #2
    Re: sending array with POST from a hidden input form field?


    "pablo" <pablok@exeit.r emovethis.demon .nl> wrote in message
    news:10be7cs5am 8jk09@corp.supe rnews.com...[color=blue]
    > Dear News Groupers,
    >
    > I'am trying to send a php array with a hidden input field from a form to
    > another script.
    > The array is NOT made directly by way of <input name="arrayname[]" />.
    >
    > The array is made by normal php code and then
    > submitted between form-tags as
    > echo "<input type='hidden' name=\"arraynam e\" value=\"$arrayn ame\" />" ;
    >
    > I can see that the receiving script receives the array but it counts only[/color]
    1[color=blue]
    > item and not the presumed amount.
    >
    > Can this be done?
    > And how should it be done then?
    >
    > TIA,
    >
    > pablo
    >
    >
    >[/color]



    Turn the array into a string and submit that

    This can then be turned back into an array with




    Comment

    • Pedro Graca

      #3
      Re: sending array with POST from a hidden input form field?

      pablo wrote:[color=blue]
      > I'am trying to send a php array with a hidden input field from a form to
      > another script.
      > The array is NOT made directly by way of <input name="arrayname[]" />.
      >
      > The array is made by normal php code and then
      > submitted between form-tags as
      > echo "<input type='hidden' name=\"arraynam e\" value=\"$arrayn ame\" />" ;[/color]

      Maybe this works (not tested)

      echo "<input type='hidden' name=\"arraynam e\" value=\"",
      urlencode(seria lize($arrayname )), "\" />" ;

      [color=blue]
      > I can see that the receiving script receives the array but it counts only 1
      > item and not the presumed amount.[/color]

      and the receiving script does

      $array = unserialize($_P OST['arrayname']);

      [color=blue]
      > Can this be done?
      > And how should it be done then?[/color]

      Remember that the user can change the hidden input field.
      Perhaps it would be better to pass the array in a session variable.


      --
      USENET would be a better place if everybody read: : mail address :
      http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
      http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
      http://www.expita.com/nomime.html : to 10K bytes :

      Comment

      • ccjx

        #4
        Re: sending array with POST from a hidden input form field?

        Pedro's method is quite a good way. But if you would really want it to
        be safe (like if you are transferring secret US government data :P), you
        could try this,

        1. Generate a random string (e.g. 19235jdsnld3235 ).
        2. Serialize the array you are transferring and store it in a file with
        the filename generated using the random string.
        OR
        2. Serialize the array you are transferring and store it in a record in
        a database with another field storing the random string (as an index).
        3. <input type="hidden" name="arraydata " value="19235jds nld3235">
        4. On the new page, just use the string to read the correct datafile or
        record and Tada! you did it. ;).

        This method is relatively safe as well as it will be difficult to guess
        another random number. However, take good care when you store the file,
        make sure you keep it in another directory or in one which is not within
        the webserver root therefore increasing security.

        I hope it helps :D.

        ccjx

        Pedro Graca wrote:
        [color=blue]
        > pablo wrote:
        >[color=green]
        >>I'am trying to send a php array with a hidden input field from a form to
        >>another script.
        >>The array is NOT made directly by way of <input name="arrayname[]" />.
        >>
        >>The array is made by normal php code and then
        >>submitted between form-tags as
        >>echo "<input type='hidden' name=\"arraynam e\" value=\"$arrayn ame\" />" ;[/color]
        >
        >
        > Maybe this works (not tested)
        >
        > echo "<input type='hidden' name=\"arraynam e\" value=\"",
        > urlencode(seria lize($arrayname )), "\" />" ;
        >
        >
        >[color=green]
        >>I can see that the receiving script receives the array but it counts only 1
        >>item and not the presumed amount.[/color]
        >
        >
        > and the receiving script does
        >
        > $array = unserialize($_P OST['arrayname']);
        >
        >
        >[color=green]
        >>Can this be done?
        >>And how should it be done then?[/color]
        >
        >
        > Remember that the user can change the hidden input field.
        > Perhaps it would be better to pass the array in a session variable.
        >
        >[/color]

        Comment

        • pablo

          #5
          Re: sending array with POST from a hidden input form field?


          "pablo" <pablok@exeit.r emovethis.demon .nl> wrote in message
          news:10be7cs5am 8jk09@corp.supe rnews.com...[color=blue]
          > Dear News Groupers,
          >
          > I'am trying to send a php array with a hidden input field from a form to
          > another script.
          > The array is NOT made directly by way of <input name="arrayname[]" />.
          >
          > The array is made by normal php code and then
          > submitted between form-tags as
          > echo "<input type='hidden' name=\"arraynam e\" value=\"$arrayn ame\" />" ;
          >
          > I can see that the receiving script receives the array but it counts only[/color]
          1[color=blue]
          > item and not the presumed amount.
          >
          > Can this be done?
          > And how should it be done then?
          >
          > TIA,
          >
          > pablo[/color]

          And now I thank you for your quick response.

          I am going to try the suggested solutions in the coming week.

          THX

          pablo


          Comment

          Working...