Advertisement
benjamin_mcf

Untitled

Nov 6th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. How do I get the values of checked checkboxes in a drupal? I'd like to display them in an alert everytime one of the checkboxes is checked. Below is what i am working with:
  2.  
  3.      $query = db_select('taxonomy_term_data', 't');
  4.      $query
  5.            ->fields('t', array('vid', 'name', 'tid'))
  6.            ->condition('t.vid', 2, '=');
  7.      $result = $query->execute();
  8.      $options = array();
  9.      foreach ($result as $row) {
  10.            $options[$row->tid] = $row->name;
  11.      };
  12.      $form['mouth'] = array(
  13.            '#type'     => 'checkboxes',
  14.            '#weight'   => '11',
  15.             '#options' => $options,
  16.             '#prefix' => '<div style="background:#FF7F55;">',
  17.             '#suffix' => '</div>',
  18.             '#ajax' => array(
  19.                 'callback' => 'make_topic_chex_callback',
  20.                 'wrapper' => 'gunge',
  21.                 'method' => 'append',
  22.                 'progress' => array('type' => 'none'),
  23.             ),
  24.       );
  25.  
  26. function make_topic_chex_callback($form, $form_state) {
  27.   $derps = $form_state['values']['mouth'];
  28.   $commands = array();
  29.   $commands[] = ajax_command_alert("Alert requested at " . $derps);
  30.   return array('#type' => 'ajax', '#commands' => $commands);
  31. }
  32.  
  33. In make_topic_chex_callback , I want to alert the values of the checkboxes in $form['mouth']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement