Drupal 6 извлекает данные из массива флажков - PullRequest
1 голос
/ 11 октября 2011

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

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

$form['message_box']['products'] = array(
    '#type'     => 'checkboxes',
    '#title'    => t('What services are you interested in ?'),
    '#options'  => array(
        'home_and_auto' => t('Home & 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 Ответ

1 голос
/ 11 октября 2011
$opts = array(
  'home_and_auto' => t('Home & 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...