简体   繁体   English

如何在Drupal 7中编辑复选框值

[英]how to edit checkbox values in drupal 7

Initially i am inserting multiple ids through multiple checkboxes. 最初,我通过多个复选框插入多个ID。 Now i want to open that page again for edit but i want some of the checkbox checked based on id i have inserted priviously. 现在,我想再次打开该页面进行编辑,但是我想根据我私下插入的ID选中某些复选框。

$courses contains all the nodes which i need to desplay and $checkedarray are the nodes which comes from database [id which got inserted after submission]. $ courses包含我需要显示的所有节点,$ checkedarray是来自数据库的节点 [提交后插入的ID]。 here is the code to uderstand the work.. 这是了解工作的代码。

$vocabulary = taxonomy_vocabulary_machine_name_load('xxx list');    
$terms = taxonomy_get_tree($vocabulary->vid);
$courses = array();
foreach($terms as $term) {
    if($term->parents[0]==0){           
        $courses[$term->tid] = $term->name."<br />";
    }
    else{
        $parents = taxonomy_get_parents($term->tid);            
        $parentsName = $parents[$term->parents[0]]->name.' / ';
        $courses[$term->tid] = $parentsName.$term->name."<br />";
    }

}

$form['addlicense']['categories'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Series'),
    '#options' => $courses,
    '#attributes' => array('class' => array('series-list')),
    '#required' => TRUE,     

);

$checkedarray = array(5,6,7,8,9,10); $ checkedarray = array(5,6,7,8,9,10); Now i have list of node which need to be appered as checked checkboxes which is in $checkedarray array... any help whould be appreciated 现在我有需要加为$ checkedarray数组中的选中复选框的节点列表...任何帮助,不胜感激

您是否尝试过使用#default_value属性并将其设置为$ checkdarray?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM