我有一个表格的2D数组,方法= POST,我希望在这里使用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>
并使用以下输入(2行): {Subject1,M} {Subject2 T,W} 我期待PHP将获取$ _POST变量:
'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)
^ var_dump($ _ POST)的结果;但它把它取为:
'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)
我该怎么做才能正确获取值?
答案 0 :(得分:0)
将所有checkbox
名称更改为days[]
,并在您的php文件中使用此代码$_POST['days']
。这将返回所有选定的值。