欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Drupal Form Checkbox having different name and id (of my choice)

shiping1 的头像
As drupal assigns title as both id and name to a form element.
$form['wrapper'][$unitClean.'_container'][$unitClean.'_cb'] = array(
                '#type' =>'checkbox', 
                '#title' => t($unit),
                );

I need name and id to be different for checkboxes, textboxes and select lists. Anybody with any idea?

I want to do this because I am populating multiple form elements in a loop, need to manipulate them using JS (in form of groups) and then process them on next page.

正确答案 
 

Found answer, done like this:

$form['wrapper'][$unitClean.'_container'][$unitClean.'_cb'] = array(
                '#type' =>'checkbox', 
                '#title' => t($unit),
                '#attributes' => array(
                  'name' => $unitClean.'_name',
                  'id' => $unitClean.'_id',
                  'onclick' => 'checkall();'                 
                    )
                );

普通分类: