在Codeigniter中,我试图以这种方式为网站选项填充4个复选框
<label for="noindex"><input type="checkbox" id="noindex" value="noindex" class="" />No Index</label>
<label for="nofollow"><input type="checkbox" id="nofollow" value="nofollow" class="" />No Follow</label>
.....and so on
我想使用数组来填充而不是为每个代码编写代码。我在这里尝试使用数组
<div class="form-group">
<?= form_label('Search Engine', 'check', array('class' => 'col-sm-4 control-label')); ?>
<div class="col-sm-6">
<?php
$checkboxes = array('noindex', 'nofollow', 'noarchive', 'nosnippet');
foreach($checkboxes as $check):
$data = array(
'name' => $check,
'id' => $check,
'value' => $check,
'class' => '',
);
$labels_text = array('No Index', 'No Follow', 'No Archive', 'No Snippet');
//print_r($check);
echo '<div class="checkbox">';
foreach ($labels_text as $label_text):
echo form_label(form_checkbox($data) . $label_text, $check.'-label', array('for' => $check));
endforeach;
//echo form_checkbox($data);
echo '</div>';
endforeach;
?>
</div>
</div>
我坚持使用标签。我希望为每个复选框显示不同的标签。
有人可以帮助我为每个人制作不同的标签吗?
答案 0 :(得分:1)
试试这样:
$checkboxes = array('noindex'=>'No Index', 'nofollow'=>'No Follow','noarchive'=>'No Archive', 'nosnippet'=>'No Snippet');
foreach($checkboxes as $check=>$label_text):
$data = array(
'name' => $check,
'id' => $check,
'value' => $check,
'class' => '',
);
echo '<div class="checkbox">';
echo form_label(form_checkbox($data) . $label_text, $check.'-label', array('for' => $check));
echo '</div>';
endforeach;