我从表单数组中的$ _post ['diet_info']发送数据。以下是数据发送的表单字段。
<table>
<tr><td></td><td align="center">Breakfast</td><td align="center">Snack1</td><td align="center">Lunch</td><td align="center">Snack2</td><td align="center">Dinner</td></tr>
<tr><td>Monday</td><td><textarea class="diet_textarea" name="diet_info['mon_breakfast']" id="mon_breakfast"></textarea></td><td><textarea class="diet_textarea" name="diet_info['mon_snack1']" id="mon_snack1"></textarea></td><td><textarea class="diet_textarea" name="diet_info['mon_lunch']" id="mon_lunch"></textarea></td><td><textarea class="diet_textarea" name="diet_info['mon_snack2']" id="mon_snack2"></textarea></td><td><textarea class="diet_textarea" name="diet_info['mon_dinner']" id="mon_dinner"></textarea></td></tr>
<tr><td>Tuseday</td><td><textarea class="diet_textarea" name="diet_info['tuse_breakfast']" id="tuse_breakfast"></textarea></td><td><textarea class="diet_textarea" name="diet_info['tuse_snack1']" id="tuse_snack1"></textarea></td><td><textarea class="diet_textarea" name="diet_info['tuse_lunch']" id="tuse_lunch"></textarea></td><td><textarea class="diet_textarea" name="diet_info['tuse_snack2']" id="tuse_snack2"></textarea></td><td><textarea class="diet_textarea" name="diet_info['tuse_dinner']" id="tuse_dinner"></textarea></td></tr>
<tr><td>Wednesday</td><td><textarea class="diet_textarea" name="diet_info['wed_breakfast']" id="wed_breakfast"></textarea></td><td><textarea class="diet_textarea" name="diet_info['thu_snack1']" id="thu_snack1"></textarea></td><td><textarea class="diet_textarea" name="diet_info['wed_lunch']" id="wed_lunch"></textarea></td><td><textarea class="diet_textarea" name="diet_info['wed_snack2']" id="mon_snack1"></textarea></td><td><textarea class="diet_textarea" name="diet_info['wed_dinner']" id="wed_dinner"></textarea></td></tr>
<tr><td>Thursday</td><td><textarea class="diet_textarea" name="diet_info['thu_breakfast']" id="thu_breakfast"></textarea></td><td><textarea class="diet_textarea" name="diet_info['thu_snack1']" id="thu_snack1"></textarea></td><td><textarea class="diet_textarea" name="diet_info['thu_lunch']" id="thu_lunch"></textarea></td><td><textarea class="diet_textarea" name="diet_info['thu_snack2']" id="thu_snack2"></textarea></td><td><textarea class="diet_textarea" name="diet_info['thu_dinner']" id="thu_dinner"></textarea></td></tr>
<tr><td>Friday</td><td><textarea class="diet_textarea" name="diet_info['fri_breakfast']" id="fri_breakfast"></textarea></td><td><textarea class="diet_textarea" name="diet_info['fri_snack1']" id="fri_snack1"></textarea></td><td><textarea class="diet_textarea" name="diet_info['fri_lunch']" id="fri_lunch"></textarea></td><td><textarea class="diet_textarea" name="diet_info['fri_snack2']" id="fri_snack2"></textarea></td><td><textarea class="diet_textarea" name="diet_info['fri_dinner']" id="fri_dinner"></textarea></td></tr>
<tr><td>Saturday</td><td><textarea class="diet_textarea" name="diet_info['sat_breakfast']" id="sat_breakfast"></textarea></td><td><textarea class="diet_textarea" name="diet_info['sat_snack1']" id="sat_snack1"></textarea></td><td><textarea class="diet_textarea" name="diet_info['sat_lunch']" id="sat_lunch"></textarea></td><td><textarea class="diet_textarea" name="diet_info['sat_snack2']" id="sat_snack2"></textarea></td><td><textarea class="diet_textarea" name="diet_info['sat_dinner']" id="sat_dinner"></textarea></td></tr>
<tr><td>Sunday</td><td><textarea class="diet_textarea" name="diet_info['sun_breakfast']" id="sun_breakfast"></textarea></td><td><textarea class="diet_textarea" name="diet_info['sun_snack1']" id="sun_snack1"></textarea></td><td><textarea class="diet_textarea" name="diet_info['sun_lunch']" id="sun_lunch"></textarea></td><td><textarea class="diet_textarea" name="diet_info['sun_snack2']" id="sun_snack2"></textarea></td><td><textarea class="diet_textarea" name="diet_info['sun_dinner']" id="sun_dinner"></textarea></td></tr>
收到请求后,我将其视为相应的
$new = serialize($_POST['diet_info']);
update_post_meta($post_id, 'diet_info', $new);
现在,在反序列化后,我需要通过键的帮助获得单值。这是我的代码
<?php $diet_info = unserialize( get_post_meta($post->ID, 'diet_info', true) ); ?>
<textarea class="diet_textarea" name="diet_info['mon_breakfast']" id="mon_breakfast"><?php echo $diet_info['mon_breakfast'];?></textarea>
通过使用这种方法我无法获得价值任何人都可以帮助我吗?
答案 0 :(得分:1)
name="diet_info['thu_breakfast']"
在您的HTML代码中removeall'(singlecode),例如
name="diet_info[thu_breakfast]"
那应该解决它。