复选框值未正确保存到 wordpress 元数组中
Checkbox values not saved correctly into a wordpress meta array
我正在尝试将数组中的复选框字段保存到用户元键中。使用以下代码,我收到以下错误:
Notice: Undefined offset: 1 in xyz path on line 54 value="">
Notice:Undefined offset: 2 in xyz path on line 54 value="">
Notice: Undefined offset: 3 in xyz path on line 54 value="">
Notice: Undefined offset: 4 in xyz path on line 54 value="">
Notice: Undefined offset: 5 in xyz path on line 54 value="">
Notice: Undefined offset: 6 in xyz path on line 54 value="">
$dps_is_store_closed = get_user_meta($user_id, '_dps_is_store_closed', true);
$daysweek2 = array(
'0' => 'Monday',
'1' => 'Tuesday',
'2' => 'Wednesday',
'3' => 'Thursday',
'4' => 'Friday',
'5' => 'Saturday',
'6' => 'Sunday',
);
<table border="0">
<tr>
<th>Closed for the Day</th>
</tr>
<tr>
foreach($daysweek2 as $key => $value){
<td>
<input type="checkbox" id="dps_is_store_closed[<?php $key?>]" name="dps_is_store_closed[<?php $key?>]" <?php checked( $dps_is_store_closed[$key], 'on' ); ?> value="">
</td>
}
</tr>
你的输入标签应该是:
id="dps_is_store_closed[<?php echo $key;?>]"
改为:
id="dps_is_store_closed[<?php $key?>]"
并且:
name="dps_is_store_closed[<?php echo $key;?>]"
改为:
name="dps_is_store_closed[<?php $key?>]"
我正在尝试将数组中的复选框字段保存到用户元键中。使用以下代码,我收到以下错误:
Notice: Undefined offset: 1 in xyz path on line 54 value="">
Notice:Undefined offset: 2 in xyz path on line 54 value="">
Notice: Undefined offset: 3 in xyz path on line 54 value="">
Notice: Undefined offset: 4 in xyz path on line 54 value="">
Notice: Undefined offset: 5 in xyz path on line 54 value="">
Notice: Undefined offset: 6 in xyz path on line 54 value="">
$dps_is_store_closed = get_user_meta($user_id, '_dps_is_store_closed', true);
$daysweek2 = array(
'0' => 'Monday',
'1' => 'Tuesday',
'2' => 'Wednesday',
'3' => 'Thursday',
'4' => 'Friday',
'5' => 'Saturday',
'6' => 'Sunday',
);
<table border="0">
<tr>
<th>Closed for the Day</th>
</tr>
<tr>
foreach($daysweek2 as $key => $value){
<td>
<input type="checkbox" id="dps_is_store_closed[<?php $key?>]" name="dps_is_store_closed[<?php $key?>]" <?php checked( $dps_is_store_closed[$key], 'on' ); ?> value="">
</td>
}
</tr>
你的输入标签应该是:
id="dps_is_store_closed[<?php echo $key;?>]"
改为:
id="dps_is_store_closed[<?php $key?>]"
并且:
name="dps_is_store_closed[<?php echo $key;?>]"
改为:
name="dps_is_store_closed[<?php $key?>]"