2

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'];
    }
  • Could you add the definition of the $form['mltag_new'] element as well? – Clive Aug 13 '12 at 14:59
  • added.. this is a part of the add/edit article page – geeky_bat Aug 13 '12 at 15:06
  • I might be missing something but you say the options are added by an ajax callback...I don't see the #ajax property anywhere on your form, have you added it in another bit of code? – Clive Aug 13 '12 at 15:09
  • the ajax property is activated on a button press.. i didn't add it earlier just to keep things simpler and short.. but wait I'll add it now and also my ajax function call – geeky_bat Aug 13 '12 at 15:13
  • @Clive- I just noticed the HTML for the checkbox that gets rendered by using the above code- <input type="checkbox" value="scientist" class="form-checkbox"> could this possibly be the cause of error ? – geeky_bat Aug 13 '12 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.