Sending an array from a form

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

    Sending an array from a form

    Hello,
    How do I send an array from a form to another php page?I want to bundle
    up some data from form fields in an array and send them together like that.
    I must be missing something?
    Thanks
    Mike


  • d

    #2
    Re: Sending an array from a form

    serialize() :)

    Generates a storable representation of a value


    You also might want to look at base64_encode, as that will make it less
    obvious what it is (and safer for moving around).

    dave

    "Mike" <someone@micros oft.com> wrote in message
    news:Mv4zf.7033 $8r1.4445@trndn y01...[color=blue]
    > Hello,
    > How do I send an array from a form to another php page?I want to bundle
    > up some data from form fields in an array and send them together like
    > that. I must be missing something?
    > Thanks
    > Mike
    >[/color]


    Comment

    • Kimmo Laine

      #3
      Re: Sending an array from a form

      "Mike" <someone@micros oft.com> wrote in message
      news:Mv4zf.7033 $8r1.4445@trndn y01...[color=blue]
      > Hello,
      > How do I send an array from a form to another php page?I want to bundle
      > up some data from form fields in an array and send them together like
      > that. I must be missing something?
      > Thanks
      > Mike[/color]


      <html><body>
      <form action="<?php echo $_SERVER['PHP_SELF']?>" method="get">
      <input type="text" name="myarray[]" value="you">
      <input type="text" name="myarray[]" value="mean">
      <input type="text" name="myarray[17]" value="like">
      <input type="text" name="myarray[dog]" value="this?">
      <input type="submit">
      </form>
      <?php print_r($_GET['myarray']); ?>
      </body></html>

      --
      "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
      spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)


      Comment

      • d

        #4
        Re: Sending an array from a form

        "Kimmo Laine" <spam@outolempi .net> wrote in message
        news:3g5zf.3543 $wM4.541@reader 1.news.jippii.n et...[color=blue]
        > "Mike" <someone@micros oft.com> wrote in message
        > news:Mv4zf.7033 $8r1.4445@trndn y01...[color=green]
        >> Hello,
        >> How do I send an array from a form to another php page?I want to
        >> bundle up some data from form fields in an array and send them together
        >> like that. I must be missing something?
        >> Thanks
        >> Mike[/color]
        >
        >
        > <html><body>
        > <form action="<?php echo $_SERVER['PHP_SELF']?>" method="get">
        > <input type="text" name="myarray[]" value="you">
        > <input type="text" name="myarray[]" value="mean">
        > <input type="text" name="myarray[17]" value="like">
        > <input type="text" name="myarray[dog]" value="this?">
        > <input type="submit">
        > </form>
        > <?php print_r($_GET['myarray']); ?>
        > </body></html>[/color]

        serialize is a lot easier ;)
        [color=blue]
        >
        > --
        > "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
        > spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)
        >[/color]


        Comment

        • Kimmo Laine

          #5
          Re: Sending an array from a form

          Kimmo Laine <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id>
          "d" <d@example.co m> kirjoitti
          viestissä:Hb6zf .2613$wl.1928@t ext.news.blueyo nder.co.uk...[color=blue]
          > "Kimmo Laine" <spam@outolempi .net> wrote in message
          > news:3g5zf.3543 $wM4.541@reader 1.news.jippii.n et...[color=green]
          >> "Mike" <someone@micros oft.com> wrote in message
          >> news:Mv4zf.7033 $8r1.4445@trndn y01...[color=darkred]
          >>> Hello,
          >>> How do I send an array from a form to another php page?I want to
          >>> bundle up some data from form fields in an array and send them together
          >>> like that. I must be missing something?
          >>> Thanks
          >>> Mike[/color]
          >>
          >>
          >> <html><body>
          >> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="get">
          >> <input type="text" name="myarray[]" value="you">
          >> <input type="text" name="myarray[]" value="mean">
          >> <input type="text" name="myarray[17]" value="like">
          >> <input type="text" name="myarray[dog]" value="this?">
          >> <input type="submit">
          >> </form>
          >> <?php print_r($_GET['myarray']); ?>
          >> </body></html>[/color]
          >
          > serialize is a lot easier ;)
          >[/color]


          Sure it is, but I understood that the data for the array would come from the
          fields of the form, while using serialize, the data should already be
          available at the script, serialized there and echoed to a value a form
          field. Depending on what the original poster really asked, both of these
          could be valid solutions. I just assumed that he wanted the values of the
          array from the form fields, of course I could be wrong.

          --
          SETI @ Home - Donate your cpu's idle time to science.
          Further reading at <http://setiweb.ssl.ber keley.edu/>


          Comment

          • d

            #6
            Re: Sending an array from a form

            "Kimmo Laine" <spam@outolempi .net> wrote in message
            news:dqj4to$g7f $1@phys-news4.kolumbus. fi...[color=blue]
            > Kimmo Laine <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id>
            > "d" <d@example.co m> kirjoitti
            > viestissä:Hb6zf .2613$wl.1928@t ext.news.blueyo nder.co.uk...[color=green]
            >> "Kimmo Laine" <spam@outolempi .net> wrote in message
            >> news:3g5zf.3543 $wM4.541@reader 1.news.jippii.n et...[color=darkred]
            >>> "Mike" <someone@micros oft.com> wrote in message
            >>> news:Mv4zf.7033 $8r1.4445@trndn y01...
            >>>> Hello,
            >>>> How do I send an array from a form to another php page?I want to
            >>>> bundle up some data from form fields in an array and send them together
            >>>> like that. I must be missing something?
            >>>> Thanks
            >>>> Mike
            >>>
            >>>
            >>> <html><body>
            >>> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="get">
            >>> <input type="text" name="myarray[]" value="you">
            >>> <input type="text" name="myarray[]" value="mean">
            >>> <input type="text" name="myarray[17]" value="like">
            >>> <input type="text" name="myarray[dog]" value="this?">
            >>> <input type="submit">
            >>> </form>
            >>> <?php print_r($_GET['myarray']); ?>
            >>> </body></html>[/color]
            >>
            >> serialize is a lot easier ;)
            >>[/color]
            >
            >
            > Sure it is, but I understood that the data for the array would come from
            > the fields of the form, while using serialize, the data should already be
            > available at the script, serialized there and echoed to a value a form
            > field. Depending on what the original poster really asked, both of these
            > could be valid solutions. I just assumed that he wanted the values of the
            > array from the form fields, of course I could be wrong.[/color]

            Well noticed :) I guess his question was a bit ambiguous - your solution is
            exactly what he needs if he wants to populate an array directly from a form.

            Makes me wonder why people don't read the documentation ;)
            [color=blue]
            > --
            > SETI @ Home - Donate your cpu's idle time to science.
            > Further reading at <http://setiweb.ssl.ber keley.edu/>
            >[/color]


            Comment

            • ampeloso@gmail.com

              #7
              Re: Sending an array from a form

              I am the original poster.(Differe nt login-google).
              To Kimmo: Now I have 2 ways of doing it. How long would it have been
              for me to learn both ways.
              So the reply to you're comment "Makes me wonder why people don't read
              the documentation ;)" (which we all see at least once in every long
              post) is
              I (We) do read the documentation. But:
              A. Sometimes we cant find what we're looking for fast enough.If we
              knew the answer we wouldnt ask.
              B. Sometimes we cant find what we're looking for .
              C. More often you get better advice from other people.
              Thanks,
              Mike

              Comment

              • ampeloso@gmail.com

                #8
                Re: Sending an array from a form

                Sorry,That was to "d"

                Comment

                • Bob_M

                  #9
                  Re: Sending an array from a form

                  On Tue, 17 Jan 2006 11:26:36 GMT, "Mike" <someone@micros oft.com>
                  wrote:
                  [color=blue]
                  >Hello,
                  > How do I send an array from a form to another php page?I want to bundle
                  >up some data from form fields in an array and send them together like that.
                  >I must be missing something?
                  >Thanks
                  >Mike
                  >[/color]
                  Just my $.02 worth:

                  I'm doing the same thing with multiple multi-dimensional arrays that
                  must pass from one form to another. Advice received from this site
                  recommended storing the arrays in $_SESSION['array_name'] and it works
                  just fine.

                  There, you now have THREE ways to do the same thing. And I, too, DO
                  read the manuals, the docs, buy the book, subscribe to the mags, etc.,
                  and I STILL ask here because here (and other forums) provide REAL
                  WORLD ANSWERS that seem to work.

                  After all, we read these forums to learn and, if possible, to share
                  our knowledge and help someone else.

                  Bob

                  Comment

                  • Mladen Gogala

                    #10
                    Re: Sending an array from a form

                    On Tue, 17 Jan 2006 11:26:36 +0000, Mike wrote:
                    [color=blue]
                    > Hello,
                    > How do I send an array from a form to another php page?I want to bundle
                    > up some data from form fields in an array and send them together like that.
                    > I must be missing something?
                    > Thanks
                    > Mike[/color]

                    You can always implode the array ("join", for the fans of the
                    OTHER scripting language) and send it as a single string.

                    --


                    Comment

                    Working...