April 7th, 2017, 05:42 AM
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?
<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.
April 7th, 2017, 06:47 AM
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?
April 7th, 2017, 07:10 AM
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.
April 13th, 2017, 01:29 PM
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.
-- Cigars, whiskey and wild, wild women. --