I have an 2D array of form, method=POST, where I want to get the days on which a subject have classes using input type=checkbox.
<input type='text' name='subject[]' />
<label> <input type='checkbox' name='monday[]' value='M'>M</label>
<label> <input type='checkbox' name='tuesday[]' value='T'>T</label>
<label> <input type='checkbox' name='wednesday[]' value='W'>W</label>
<label> <input type='checkbox' name='thursday[]' value='Th'>Th</label>
<label> <input type='checkbox' name='friday[]' value='F'>F</label>
<label> <input type='checkbox' name='saturday[]' value='Sa'>Sa</label>
<input type='text' name='subject[]' />
<label> <input type='checkbox' name='monday[]' value='M'>M</label>
<label> <input type='checkbox' name='tuesday[]' value='T'>T</label>
<label> <input type='checkbox' name='wednesday[]' value='W'>W</label>
<label> <input type='checkbox' name='thursday[]' value='Th'>Th</label>
<label> <input type='checkbox' name='friday[]' value='F'>F</label>
<label> <input type='checkbox' name='saturday[]' value='Sa'>Sa</label>
and with the following inputs (2 rows): {Subject1, M} {Subject2 T, W} I am expecting that PHP will fetch the $_POST variable as:
'subject' =>
array (size=2)
0 => string 'Subject1' (length=8)
1 => string 'Subject2' (length=8)
'monday' =>
array (size=1)
**1 => string 'M' (length=1)**
'tuesday' =>
array (size=1)
0 => string 'T' (length=1)
'wednesday' =>
array (size=1)
0 => string 'W' (length=1)
^result from var_dump($_POST); but it fetch it as:
'subject' =>
array (size=2)
0 => string 'Subject1' (length=8)
1 => string 'Subject2' (length=8)
'monday' =>
array (size=1)
**0 => string 'M' (length=1)**
'tuesday' =>
array (size=1)
0 => string 'T' (length=1)
'wednesday' =>
array (size=1)
0 => string 'W' (length=1)
what should I do to fetch the values correctly?
Change all checkbox
name as days[]
and in your php file use this code $_POST['days']
. this will returns all selected values.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.