Professional Web Applications Themes

checkboxes and arrays - PHP Development

Marcus <JumpMan222aol.com> wrote: > For example purposes, say I am dealing with 3 checkboxes ($num_services > here is 3). Regardless of which boxes I actually choose, it will "push" > the checked values to the front, i.e. if I select box1 and box 3, which > I THINK are $offers[0] and $offers[2], when I test it will say that I > have selected box 1 and box 2 instead of 1 and 3. Likewise, if I choose Stop guessing what the input is and check what our input _really_ is: phpinfo(32) is your friend. -- Daniel Tryba...

  1. #1

    Default Re: checkboxes and arrays

    Marcus <JumpMan222aol.com> wrote:
    > For example purposes, say I am dealing with 3 checkboxes ($num_services
    > here is 3). Regardless of which boxes I actually choose, it will "push"
    > the checked values to the front, i.e. if I select box1 and box 3, which
    > I THINK are $offers[0] and $offers[2], when I test it will say that I
    > have selected box 1 and box 2 instead of 1 and 3. Likewise, if I choose
    Stop guessing what the input is and check what our input _really_ is:
    phpinfo(32) is your friend.

    --

    Daniel Tryba
    Daniel Tryba Guest

  2. #2

    Default Re: checkboxes and arrays

    Zurab Davitiani wrote:
    > Only checked checkboxes are being sent in the submitted form. Unchecked
    > checkboxes are not being sent. Since all your checkboxes are called
    > offers[], PHP automatically assigns array keys to them. Hence, your
    > results. This is correct and expected behavior.
    >
    > To avoid this, either name your checkboxes to offers[0], offers[1], etc. at
    > the time they are generated AND/OR use distinct checkbox value properties
    > to verify which ones were submitted.
    >
    Wow, thank you for the help, it works perfectly now... if it helps
    anyone else with a similar problem, i was using a for loop to create my
    checkboxes, and $i was the variable used for iteration... so if you need
    to do this too, make sure you name your array checkbox[$i] instead of
    just checkbox[]. I did a similar thing with textboxes recently and with
    those if you use a forloop, you can just name the array textbox[]
    without the $i... I guess checkboxes just behave differently.

    Marcus

    Marcus Guest

  3. #3

    Default Re: checkboxes and arrays

    Marcus <JumpMan222aol.com> wrote:
    > thought... checking any box results in:
    >
    > Array
    > (
    > [0] => yes
    > )
    >
    > checking any two boxes results in:
    >
    > Array
    > (
    > [0] => yes
    > [1] => yes
    > )
    >
    > etc.
    >
    > This still doesn't help me figure out why it isn't taking the correct
    > values however. Any other suggestions?
    Although you seem to have your problem resolved, in the future you might
    want to post some sample code (small, easy to read and to the point)
    with your question, that would help a lot :)

    --

    Daniel Tryba

    Daniel Tryba Guest

Similar Threads

  1. Nesting Arrays within arrays.
    By JimmySlam in forum Macromedia Flash Ad Development
    Replies: 3
    Last Post: March 15th, 09:42 AM
  2. PHP checkboxes
    By philphanluvr@hotmail.com in forum PHP Development
    Replies: 4
    Last Post: September 29th, 10:38 PM
  3. [PHP] Checkboxes
    By Matt Babineau in forum PHP Development
    Replies: 2
    Last Post: August 15th, 06:52 PM
  4. ASP.NET Checkboxes
    By Tracey in forum ASP.NET General
    Replies: 0
    Last Post: July 23rd, 05:01 PM
  5. CGI and checkboxes
    By Kurt M. Dresner in forum Ruby
    Replies: 3
    Last Post: July 14th, 10:23 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139