#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2017
    Posts
    1
    Rep Power
    0

    hidden inputs with same name: how to send only the values of selected checkboxes?


    Within a php environment we have one checkbox linked to one hidden field with the SAME NAME ($name). How could we send only the values of the selected checkboxes?

    php
    <input type"checkbox" name="<?echo $filename;?>_<?echo $variable;?>"
    id="filename_<?echo $variable;?>" value="1">

    <input type="hidden" name="item_<?echo $filename;?>" value="<?echo $quantity;?>">

    In the generated html this checkbox with its own hidden file is then repeted several time with different name ($name).

    How can we stop the form to send the value of the unchecked hidden inputs? We cannot use different names nor an array. In the next php page we need to get a single value from each hidden input.
    We cannot use the array "method" as we then need to use only one variable in a second page rather than the whole array. We cannot "GET" one element via its position within the array as such a position is determined by the individual choice of the end user via a checkbox.
  2. #2
  3. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,177
    Rep Power
    9644
    So you want the value of the hidden input if the checkbox is not checked, and the value of the checkbox (1) if it is checked?
  4. #3
  5. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,118
    Rep Power
    2010
    You refer to a variable called $name, which is not part of you code.
    I can see what part have same name, the checkbox only use a combination of filename and a variable, where the hidden field use the filename with 'item_' as prefix.

    That said, no matter what you expect your forms to do/send, you can't trust anything of it. As soon you get input from outside (e.g. a user) you must validate everything.
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,733
    Rep Power
    4536
    You can't stop a hidden value/item from being sent along with the POST/GET data.

    I think it would help if you took a step back and explained what you're trying to accomplish and maybe a bit of what you want the sample HTML code to look like.

    This is a bit like trying to solve your problem without ever knowing what the question was.

    -John
    -- Cigars, whiskey and wild, wild women. --

IMN logo majestic logo threadwatch logo seochat tools logo