Drupal 6 извлекает данные из массива чекбоксов

#drupal

#drupal

Вопрос:

В настоящее время я работаю над модулем пользовательской формы в Drupal 6. В этой форме я использую поле флажков с примерно 10 различными параметрами. Проблема, с которой я, похоже, сталкиваюсь, заключается в том, что единственный вывод, который я получаю от флажков, — это «массив». Я потратил пару часов на поиск в Google, как сумасшедший, и нашел множество руководств о том, как создавать флажки, но ни один из них не описывает, что делать с данными после их ввода.

Вот код флажка:

 $form['message_box']['products'] = array(
    '#type'     => 'checkboxes',
    '#title'    => t('What services are you interested in ?'),
    '#options'  => array(
        'home_and_auto' => t('Home amp; Auto Insurance'),
        'auto'          => t('Auto Insurance'), 
        'home'          => t('Home Insurance'),
        'other'         => t('Other Personal Insurance'),
        'business'      => t('Business Insurance'),
        'farm'          => t('Farm Insurance'),
        'life'          => t('Life Insurance'),
        'health'        => t('Health Insurance'),
        'rv'            => t('Recreational Vehicle Insurance'),
        'financial'     => t('Financial Services'),
        ),
    '#weight'   => 39
    );      
  

Я установил переменную для массива

 $products = $form_state['values']['products'];
  

И код для тела электронного письма:

     $body = 'New quote request from '.$sender.'<br><br>Email Address :'.$valid_email.'<br>'.'Phone No :'.$phone.'<br><br>'.'Address :<br>'.$street.'<br>'.$city.', '.$state.'<br>'.$zip.'<br><br>Interested in the following products<br>'.$products.'<br><br>'.$emessage;
  

Спасибо за любую помощь, которую вы можете предоставить.

Ответ №1:

 $opts = array(
  'home_and_auto' => t('Home amp; Auto Insurance'),
  'auto'          => t('Auto Insurance'), 
  'home'          => t('Home Insurance'),
  'other'         => t('Other Personal Insurance'),
  'business'      => t('Business Insurance'),
  'farm'          => t('Farm Insurance'),
  'life'          => t('Life Insurance'),
  'health'        => t('Health Insurance'),
  'rv'            => t('Recreational Vehicle Insurance'),
  'financial'     => t('Financial Services'),
);
$form['your_possibledynamyc_opts'] = array(
  '#type' => 'value',
  '#value' => $opts,
);

$form['message_box']['products'] = array(
  '#type'     => 'checkboxes',
  '#title'    => t('What services are you interested in ?'),
  '#options'  => $opts,
  '#weight'   => 39,
);      

// in submit function
$products = array();
foreach ($form_state['values']['your_possibledynamyc_opts'] as $key => $val) {
  if ($form_state['values']['products'][$key]) {
    $products[] = $val;
  }
}
$products = implode(', ', $products); // Here text of selected products by comma