-
-
Save hexblot/9052139 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file megaselect.module | |
* TODO: Enter file description here. | |
*/ | |
/** | |
* Implements hook_menu(). | |
*/ | |
function megaselect_menu() { | |
$items['megaselect'] = array( | |
'title' => 'Megaselect', | |
'page callback' => 'drupal_get_form', | |
'page arguments' => array('megaselect_megaform'), | |
'access arguments' => array('access content'), | |
'type' => MENU_CALLBACK, | |
); | |
return $items; | |
} | |
function megaselect_megaform($form, $form_state) | |
{ | |
$users = array | |
( | |
array('uid' => 1, 'first_name' => 'Indy', 'last_name' => 'Jones' | |
, 'nicknames' => array('indy', 'andy', 'pandy')), | |
array('uid' => 2, 'first_name' => 'Darth', 'last_name' => 'Vader' | |
, 'nicknames' => array('durth', 'dearth', 'dark')), | |
array('uid' => 3, 'first_name' => 'Super', 'last_name' => 'Man' | |
, 'nicknames' => array('supper', 'dessert', 'stormy', 'catcherman')), | |
); | |
$header = array | |
( | |
'first_name' => t('First Name'), | |
'last_name' => t('Last Name'), | |
'nick_name' => t('Nick Name'), | |
); | |
$options = array(); | |
foreach($users as $user) | |
{ | |
$rowid = $user['uid']; | |
$inneroptions = drupal_map_assoc($user['nicknames']); | |
foreach($inneroptions as &$option) { | |
$option = array('nick' => $option); | |
} | |
$innerheader = array('nick' => 'Choose a Nickname'); | |
$innerform = array ( | |
'#type' => 'tableselect', | |
'#header' => $innerheader, | |
'#options' => $inneroptions, | |
'#multiple' => FALSE, | |
'#title' => 'Nickname', | |
'#title_display' => 'invisible', | |
'#parents' => array('nickname-row', $rowid), | |
'#default_value' => '', | |
'#id' => 'nickname_row' . $rowid . '', | |
'#name' => 'nickname[row' . $rowid . ']', | |
'#empty' => t('No nicknames to choose from'), | |
); | |
$innerform = form_process_tableselect($innerform); | |
// dpm($inneroptions, 'inner options'); | |
$options[$rowid] =array | |
( | |
'first_name' => $user['first_name'], | |
'last_name' => $user['last_name'], | |
'nick_name' => array('data' => array( | |
$innerform, | |
), | |
) | |
); | |
} | |
$form['table'] = array | |
( | |
'#type' => 'tableselect', | |
'#header' => $header, | |
'#options' => $options, | |
'#empty' => t('No users found'), | |
); | |
$form['nickname'] = array( | |
'#type' => 'value', | |
); | |
$form['submit'] = array | |
( | |
'#type' => 'submit', | |
'#value' => t('Submit'), | |
); | |
dpm($form); | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment