我使用have\\u字段循环遍历数组并创建复选框列表。一切似乎都很正常,只是复选框在后端没有始终显示为“选中”。下面是我使用的代码:
<?php $items = array(
\'bio\',
\'youtube\',
\'articles\',
\'learn-more\',
\'testimonials\',
\'twitter\',
\'custom\',
); ?>
<p>
<?php while ($mb->have_fields(\'t_enabled_widgets\', count($items))): ?>
<?php $item = $items[$mb->get_the_index()]; ?>
<input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $item; ?>"<?php $mb->the_checkbox_state($item); ?>/> <?php echo ucwords(str_replace("-", " ", $item )); ?><br/>
<?php endwhile; ?>
</p>
例如,当我勾选前4个框(Bio、Youtube、Articles和Learn More)时,一切都很好。当我检查第5页时,它将保存到数据库中,但当页面重新加载时,它将被取消选中。这显然是一个问题,因为当您再次“更新”页面时,它将作为空白值提交。有什么想法吗?