'form_demo', 'callback' => 'drupal_get_form', 'callback arguments' => array('form_demo_form'), 'access' => user_access('access content'), 'title' => t('Form demo'), ); } return $items; } /** * Just a simple form * * @return array */ function form_demo_form() { $form = array(); $form['fd_boxes'] = array ( '#type' => 'checkboxes', '#options' => array ( 15 => 'a', 20 => 'b', 25 => 'c', ), '#default_value' => variable_get('fd_boxes', 0), ); $form['submit'] = array ( '#type' => 'submit', '#value' => t('Test'), ); return $form; } function form_demo_form_submit($form_id, $form_values) { /** * Look at form_values: it only contains the keys to the fd_boxes array: * We're not supposed to use the captions for storage */ // dsm($form_values); // Exclude unnecessary elements. This one comes from our form: unset($form_values['submit']); // But these ones are put in by Forms API and always there unset($form_values['form_id'], $form_values['op'], $form_values['form_token']); foreach ($form_values as $key => $element) { variable_set($key, $element); // Serialized as necessary, so it will store an array } } function theme_form_demo_form($form) { /* * First we need to override some builtin styles for our form table: * - the 100% width on tables * - the display:block on form-item divs containing checkboxes */ drupal_set_html_head (' '); /* * Now we had the "Select all rows" JS magic */ $arHeader = array ( t('The option values'), theme('table_select_header_cell'), ); $arData = array(); /** * Loop on element_children, not on all array keys: we are not interested * in properties, only elements which are children of fd_boxes */ foreach (element_children($form['fd_boxes']) as $index) { $checkboxTitle = $form['fd_boxes'][$index]['#title']; // get box title unset($form['fd_boxes'][$index]['#title']); // then remove it from the box before rendering $box = drupal_render($form['fd_boxes'][$index]); // and render the box $row = array // the row itself ( $index, // its first cell, showing the actual option value array // its second cell, showing the reversed checkbox ( 'data' => "$checkboxTitle$box", 'style' => 'text-align: right', ), ); $arData[] = $row; } // Now render the table representing fd_boxes $ret = theme('table', $arHeader, $arData, array('class' => 'special-checkboxes')); // And do not forget to render the rest of the form $ret .= drupal_render($form); return $ret; }