I have my two table-select as -
$form['mltag_new']['tag'] = array(
'#type' => 'button',
'#value' => t("Suggest Tags"),
'#ajax' => array(
'callback' => 'mltag_suggest_tags_ajax',
'wrapper' => 'mltag_suggest_tags_table_div',
'effect' => 'slide',
),
);
$form['mltag_new']['myselector'] = array(
'#prefix' => '<div id="mltag_suggest_tags_table_div">',
'#suffix' => '</div>',
);
$form['mltag_new']['myselector']['implicit_tags'] = array(
'#type' => 'tableselect',
'#title' => 'My Selector',
'#header' => $header,
'#attribute' => array('style' => 'display:none;'),
);
$header_learn_tags = array(
'sno ' => t('S. No.'),
'tags' => t('Tags'),
);
$form['mltag_new']['myselector']['learn_tags'] = array(
'#type' => 'tableselect',
'#title' => 'Tags from Learning',
'#header' => $header_learn_tags,
'#attribute' => array('style' => 'display:none;'),
);
$form['#submit'][] = 'mltag_custom_submit_function';
The values- $options are being set by an ajax callback activated on the press of a button. But when I am trying to capture the values checked by the user in the table in my mltag_custom_submit_function it returns an empty array. The code I am using is-
$selected_uids = $form_state['values']['mltag_new']['myselector']['implicit_tags'];
drupal_set_message(print_r($form_state['values'], TRUE));
How can I capture the values selected by the user in the table correctly ?
Edit -
definition for $form['mltag_new']
$form['mltag_new'] = array(
'#type' => 'fieldset',
'#title' => t('MLTag settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'additional_settings',
'#tree' => TRUE,
'#weight' => -2,
'#attributes' => array('class' => array('mltag-settings')),
);
also a short snippet of my ajax function is this-
function mltag_suggest_tags_ajax($form, &$form_state) {
$output = '';
$tags = some_function_call();
$algo = variable_get('algo_type');
if ($algo == 1) {
$header = array(
'tag' => t('Tag'),
'frequency' => t('Frequency'),
);
$options = array();
foreach ($tags as $key => $value) {
$options[$key] = array(
'tag' => $key,
'frequency' => $value,
);
}
}
//returning values for tableselect
$form['mltag_new']['myselector']['implicit_tags']['#header'] = $header;
$form['mltag_new']['myselector']['implicit_tags']['#options'] = $options;
$form['mltag_new']['myselector']['implicit_tags'] = form_process_tableselect($form['mltag_new']['myselector']['implicit_tags']);
$form['mltag_new']['myselector']['learn_tags']['#header'] = $header_learn_tags;
$form['mltag_new']['myselector']['learn_tags']['#options'] = $options_learn;
$form['mltag_new']['myselector']['learn_tags'] = form_process_tableselect($form['mltag_new']['myselector']['learn_tags']);
return $form['mltag_new']['myselector'];
}
$form['mltag_new']
element as well?#ajax
property anywhere on your form, have you added it in another bit of code?