problem with checkbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hugonot
    New Member
    • May 2007
    • 4

    #1

    problem with checkbox

    I have got a problem with checkboxes array and the form.
    I have the results from table (MySQL) and checkbox (form) near the results.
    I use:
    echo "<input type=checkbox name=box[] value=".$['lp'].">";
    for checkbox i.e. I create array of checkbox.
    How can I remember the state of checkboxes in array and pass it by GET?
    I know how to do it with a single checkbox already selected inside the code:
    $next = " <a href=\"$self?pa ge=$page&amp;$b ox=13\">"."&rsa quo;"."</a>
    but I don't know how to check its state and remember.
    I use paging of the results with GET and canot use POST because it is reserved for passing data to another form.
    Any help is welcome :)
    Last edited by hugonot; May 13 '07, 05:53 PM. Reason: more clear
  • adamalton
    New Member
    • Feb 2007
    • 93

    #2
    What????

    You need to explain this clearly.

    Where does the array come from? Does it have your mysql results in it? Are you creating a page with checkboxes on it from the mysql results? Or have you got results from mysql and more results from some checkboxes? Are you trying to take a user's checkbox selections and pass them back to another page?
    ??????????????? ??????????????? ??????????????? ??????????????? ???????

    Comment

    • hugonot
      New Member
      • May 2007
      • 4

      #3
      Originally posted by adamalton
      What????
      Are you trying to take a user's checkbox selections and pass them back to another page?
      ??????????????? ??????????????? ??????????????? ??????????????? ???????
      Thanks for mail, Yes exactly I try to take users selection and pass it to previous or next page with a GET.

      I have got a table from database (sql):
      1. Letter 1 - Editor
      2. Letter 2 - Aunt
      3. Letter 3 - Johny
      The number of records can be large so I use pagging with GET.
      It works fine.
      I added form and checkbox near each record which looks like:
      1. Letter 1 - Editor [] 6
      2. Letter 2 - Aunt [] 7
      3. Letter 3 - Johny [] 9
      The value of checkbox is the record numer in database on the right side.
      I checked for example 1 and 3 record. When I am back on the same page I would like to see previously checked (selected) records, but all checkboxes are unchecked :(.
      I can not use POST (I use it to pass data for another form and it works fine).
      I know how to remember a single checkbox insied php script I put $box=2 and it works. But I have no idea how to do an array passing by GET.
      I know I should set box[] insted of box in form input. I have array of checkboxes.
      I don't know how to pass an array by GET.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        You will have to name all fields in the array the same name, followed by [].
        When posted, this data will exist as an array inside the $_REQUEST array, each field containing the value parameter of the input tag.

        For example, if you have 3 checkboxes named box[], and set the value of each from 0 to 2 and only check the first and the third.
        You will be able to access the data from the other side by doing something like this:
        [PHP]
        $_REQUEST['box'][0]; // The first checked box, value = 0
        $_REQUEST['box'][1]; // The second checked box, value = 2
        [/PHP]

        It only passes on the boxes that you checked, so the array it passes will only contain two fields, the first and the third.

        If this is unclear, you can view the entire contents of the array by doing this:
        [PHP]
        print_r($_REQUE ST['box']);
        [/PHP]

        Comment

        • hugonot
          New Member
          • May 2007
          • 4

          #5
          Many thanks, I added a line:
          echo "<input type=checkbox name=box[] value=".$d['id'].">";
          what returns a checkbox array (of course a single one for each record).
          $_REQUEST doesn't work.
          print_r is empty.
          echo '<pre>';
          var_export( $_REQUEST );
          echo '</pre>';
          returns nothing.
          It does require POST? I can use only GET.
          Help me pleeeez...

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Originally posted by hugonot
            Many thanks, I added a line:
            echo "<input type=checkbox name=box[] value=".$d['id'].">";
            what returns a checkbox array (of course a single one for each record).
            $_REQUEST doesn't work.
            print_r is empty.
            echo '<pre>';
            var_export( $_REQUEST );
            echo '</pre>';
            returns nothing.
            It does require POST? I can use only GET.
            Help me pleeeez...
            Can you give us more of your code? It is hard to debug a code you can't see :)

            First thing that jumps at me there, XHTML requires you to put variable values inside quote marks, so you should try writing your HTML like this.
            [HTML]
            <input type="checkbox" name="box[]" value="0" />
            [/HTML]

            Also, why can't you use post?

            Comment

            Working...