Adding an integer at the end of an input's name to get a specific url
Posted
by
Gadgetster
on Stack Overflow
See other posts from Stack Overflow
or by Gadgetster
Published on 2014-06-01T21:21:34Z
Indexed on
2014/06/01
21:25 UTC
Read the original article
Hit count: 140
php
I am trying to get a url where I can retrieve the selected values from. For example, if I put a check mark on a and b then sumbit, I will get:
index.php?category=1&&category=2
I want to get this instead: index.php?category0=1&&category1=2 So that I can later get this specific value with $_GET['category0']
Is there a way to add a counter for the selected checkboxes and add 0,1,2,3.. at the end of the name of its input?
<form action="" method="get">
<!-- this will be a php loop instead of hardcored
which will retrieve data from the db -->
<label><input type="checkbox" name="category" value="1">a</label>
<label><input type="checkbox" name="category" value="2">b</label>
<label><input type="checkbox" name="category" value="3">c</label>
<label><input type="checkbox" name="category" value="4">d</label>
<label><input type="checkbox" name="category" value="5">e</label>
<input type="submit">
</form>
© Stack Overflow or respective owner