checkbox array problem

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

    checkbox array problem

    Hi

    I have a form which contains several fields. One of which is a group of
    checkboxes that can all be selected, and if they are - all values should be
    passed as an array.

    Each checkbox is Named as follows. myCheckBoxName[]

    myCheckBoxName[]


    I have the following code on the following page to pick up the results from
    the querystring.

    while(list($key , $value) = each($HTTP_POST _VARS))
    {
    $keys = $keys . "$key, ";
    $values= $values . "'$value', ";
    echo("$key = $value <br>" );
    }


    But the field which contains multiple checkboxes only displays the value
    "array" - and nothing else.

    Any ideas.

    Thanks

    AL



  • AJ

    #2
    Re: checkbox array problem


    "Andy Levy" <andy_levy@hotm ail.com> wrote in message
    news:mUj1c.1045 5$Db4.7531@news-binary.blueyond er.co.uk...[color=blue]
    > Hi
    >
    > I have a form which contains several fields. One of which is a group of
    > checkboxes that can all be selected, and if they are - all values should[/color]
    be[color=blue]
    > passed as an array.
    >
    > Each checkbox is Named as follows. myCheckBoxName[]
    >
    > myCheckBoxName[]
    >
    >
    > I have the following code on the following page to pick up the results[/color]
    from[color=blue]
    > the querystring.
    >
    > while(list($key , $value) = each($HTTP_POST _VARS))
    > {
    > $keys = $keys . "$key, ";
    > $values= $values . "'$value', ";
    > echo("$key = $value <br>" );
    > }
    >
    >
    > But the field which contains multiple checkboxes only displays the value
    > "array" - and nothing else.[/color]

    As nobody has answered yet with anything definitive, I'll have a stab. I'm
    still very much in the learning stage of PHP, right at the bottom of the
    curve. I had exactly this problem with something I was doing. When I was
    testing, I was echoing strings and I got ARRAY echoed back.

    I'm afraid I can't remember exactly what I did but it was something to do
    with putting strings on double quotes, single quotes or no quotes. I just
    tried different combinations until it worked.

    I probably shouldn't be posting when I don't know the exact answer so I'll
    apologise in advance.

    Andy


    Comment

    • Tony Marston

      #3
      Re: checkbox array problem

      You cannot just write myCheckBoxName[], myCheckBoxName[], ... to the HTML
      output, it must be myCheckBoxName[1], myCheckBoxName[2], etc.

      --
      Tony Marston

      This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




      "AJ" <nospam@redcatm edia.net> wrote in message
      news:c24qoq$k68 $1@titan.btinte rnet.com...[color=blue]
      >
      > "Andy Levy" <andy_levy@hotm ail.com> wrote in message
      > news:mUj1c.1045 5$Db4.7531@news-binary.blueyond er.co.uk...[color=green]
      > > Hi
      > >
      > > I have a form which contains several fields. One of which is a group of
      > > checkboxes that can all be selected, and if they are - all values should[/color]
      > be[color=green]
      > > passed as an array.
      > >
      > > Each checkbox is Named as follows. myCheckBoxName[]
      > >
      > > myCheckBoxName[]
      > >
      > >
      > > I have the following code on the following page to pick up the results[/color]
      > from[color=green]
      > > the querystring.
      > >
      > > while(list($key , $value) = each($HTTP_POST _VARS))
      > > {
      > > $keys = $keys . "$key, ";
      > > $values= $values . "'$value', ";
      > > echo("$key = $value <br>" );
      > > }
      > >
      > >
      > > But the field which contains multiple checkboxes only displays the value
      > > "array" - and nothing else.[/color]
      >
      > As nobody has answered yet with anything definitive, I'll have a stab.[/color]
      I'm[color=blue]
      > still very much in the learning stage of PHP, right at the bottom of the
      > curve. I had exactly this problem with something I was doing. When I was
      > testing, I was echoing strings and I got ARRAY echoed back.
      >
      > I'm afraid I can't remember exactly what I did but it was something to do
      > with putting strings on double quotes, single quotes or no quotes. I just
      > tried different combinations until it worked.
      >
      > I probably shouldn't be posting when I don't know the exact answer so I'll
      > apologise in advance.
      >
      > Andy
      >
      >[/color]


      Comment

      • Andy Levy

        #4
        Re: checkbox array problem

        Hi Thanks for your post.

        I have been meddling with it a bit and came up with something that checks
        for an array. Its not quite working well yet , as the main loop causes a
        problem. See if you can do anything.


        //Variables Used
        //$key, $value, $arrayitem, $item, $text, $keys, $values

        while(list($key , $value) = each($HTTP_POST _VARS)) {
        if (is_array($valu e)):
        $arrayitem = $_POST[$key];
        foreach ($arrayitem as $item) {
        $text = $text . $item . ", ";
        }
        $text = substr($text,0,-2);

        $keys = $keys . "$key, ";
        $values= $values . "'$text', ";
        //echo("$key = $text <br>" );

        else:
        $keys = $keys . "$key, ";
        $values= $values . "'$value', ";
        //echo("$key = $value <br>" );
        endif;


        }



        "AJ" <nospam@redcatm edia.net> wrote in message
        news:c24qoq$k68 $1@titan.btinte rnet.com...[color=blue]
        >
        > "Andy Levy" <andy_levy@hotm ail.com> wrote in message
        > news:mUj1c.1045 5$Db4.7531@news-binary.blueyond er.co.uk...[color=green]
        > > Hi
        > >
        > > I have a form which contains several fields. One of which is a group of
        > > checkboxes that can all be selected, and if they are - all values should[/color]
        > be[color=green]
        > > passed as an array.
        > >
        > > Each checkbox is Named as follows. myCheckBoxName[]
        > >
        > > myCheckBoxName[]
        > >
        > >
        > > I have the following code on the following page to pick up the results[/color]
        > from[color=green]
        > > the querystring.
        > >
        > > while(list($key , $value) = each($HTTP_POST _VARS))
        > > {
        > > $keys = $keys . "$key, ";
        > > $values= $values . "'$value', ";
        > > echo("$key = $value <br>" );
        > > }
        > >
        > >
        > > But the field which contains multiple checkboxes only displays the value
        > > "array" - and nothing else.[/color]
        >
        > As nobody has answered yet with anything definitive, I'll have a stab.[/color]
        I'm[color=blue]
        > still very much in the learning stage of PHP, right at the bottom of the
        > curve. I had exactly this problem with something I was doing. When I was
        > testing, I was echoing strings and I got ARRAY echoed back.
        >
        > I'm afraid I can't remember exactly what I did but it was something to do
        > with putting strings on double quotes, single quotes or no quotes. I just
        > tried different combinations until it worked.
        >
        > I probably shouldn't be posting when I don't know the exact answer so I'll
        > apologise in advance.
        >
        > Andy
        >
        >[/color]


        Comment

        • Andy Levy

          #5
          Re: checkbox array problem

          Thanks Tony

          I have it all working now. I rewrote my PHP code, and here it is just for
          your info - or use. The array [] can be used without numbers on an html form
          when parsed by PHP as php automatically collates the data. That only goes
          if you dont want the array in any particular order.

          Heres my code ::

          while(list($key , $value) = each($HTTP_POST _VARS)) {
          if (is_array($valu e)):
          $value = implode(", ", $value);

          $keys = $keys . "$key, ";
          $values= $values . "'$value', ";
          //echo("$key = $text <br>" );

          else:
          $keys = $keys . "$key, ";
          $values= $values . "'$value', ";
          //echo("$key = $value <br>" );
          endif;

          }





          "Tony Marston" <tony@NOSPAM.de mon.co.uk> wrote in message
          news:c2501k$g1k $1$8302bc10@new s.demon.co.uk.. .[color=blue]
          > You cannot just write myCheckBoxName[], myCheckBoxName[], ... to the HTML
          > output, it must be myCheckBoxName[1], myCheckBoxName[2], etc.
          >
          > --
          > Tony Marston
          >
          > http://www.tonymarston.net
          >
          >
          >
          > "AJ" <nospam@redcatm edia.net> wrote in message
          > news:c24qoq$k68 $1@titan.btinte rnet.com...[color=green]
          > >
          > > "Andy Levy" <andy_levy@hotm ail.com> wrote in message
          > > news:mUj1c.1045 5$Db4.7531@news-binary.blueyond er.co.uk...[color=darkred]
          > > > Hi
          > > >
          > > > I have a form which contains several fields. One of which is a group[/color][/color][/color]
          of[color=blue][color=green][color=darkred]
          > > > checkboxes that can all be selected, and if they are - all values[/color][/color][/color]
          should[color=blue][color=green]
          > > be[color=darkred]
          > > > passed as an array.
          > > >
          > > > Each checkbox is Named as follows. myCheckBoxName[]
          > > >
          > > > myCheckBoxName[]
          > > >
          > > >
          > > > I have the following code on the following page to pick up the results[/color]
          > > from[color=darkred]
          > > > the querystring.
          > > >
          > > > while(list($key , $value) = each($HTTP_POST _VARS))
          > > > {
          > > > $keys = $keys . "$key, ";
          > > > $values= $values . "'$value', ";
          > > > echo("$key = $value <br>" );
          > > > }
          > > >
          > > >
          > > > But the field which contains multiple checkboxes only displays the[/color][/color][/color]
          value[color=blue][color=green][color=darkred]
          > > > "array" - and nothing else.[/color]
          > >
          > > As nobody has answered yet with anything definitive, I'll have a stab.[/color]
          > I'm[color=green]
          > > still very much in the learning stage of PHP, right at the bottom of the
          > > curve. I had exactly this problem with something I was doing. When I[/color][/color]
          was[color=blue][color=green]
          > > testing, I was echoing strings and I got ARRAY echoed back.
          > >
          > > I'm afraid I can't remember exactly what I did but it was something to[/color][/color]
          do[color=blue][color=green]
          > > with putting strings on double quotes, single quotes or no quotes. I[/color][/color]
          just[color=blue][color=green]
          > > tried different combinations until it worked.
          > >
          > > I probably shouldn't be posting when I don't know the exact answer so[/color][/color]
          I'll[color=blue][color=green]
          > > apologise in advance.
          > >
          > > Andy
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...