我在文字出版社工作,我从数据库中获取数据,并在下拉列表中显示。我的代码是这样的。
<select multiple="multiple" class="tole_int">
<?php
global $wpdb;
$query_interest = "select p.* from wp_posts as p where p.post_type = 'interests' and p.post_name !='' ";
$tolerancetypes = $wpdb->get_results($query_interest,OBJECT);
foreach($tolerancetypes as $key=>$interest)
{
?>
<option value="<?php echo $interest->ID; ?>"><?php echo ucfirst($interest->post_name); ?></option>
<?php
}
?>
</select>我已经编写了multiple=" multiple“属性,用于选择要添加的多个values.But复选框以及值。那我该写什么呢?
发布于 2015-05-12 12:10:50
试试这个“引导多重选择”
http://davidstutz.github.io/bootstrap-multiselect/
那么您就不需要手动编写复选框代码了。
发布于 2015-05-12 12:20:21
确保在Form中添加复选框,如果要在metabox中使用此复选框,不需要创建Form
因此,将selectbox更改为checkbox
<?php
global $wpdb;
$query_interest = "select p.* from wp_posts as p where p.post_type = 'interests' and p.post_name !='' ";
$tolerancetypes = $wpdb->get_results($query_interest,OBJECT);
foreach($tolerancetypes as $key=>$interest)
{
?>
<input type="checkbox" name="tole_int[]" value="<?php echo $interest->ID; ?>" /><?php echo $interest->post_title; ?>
<?php
}在提交表单时,可以获得由逗号分隔的值并保存。
$tole_int = implode(",", $_POST['tole_int']);或者如果要检查多个复选框值的输出,请尝试
echo '<pre>';print_r($_POST['tole_int']);echo '</pre>';https://stackoverflow.com/questions/30190391
复制相似问题