Drupal 6 pulling data from checkbox array
I am currently working on a custom form module in Drupal 6. In this form I am using a checkboxes field with about 10 different options. The problem I seem to be having is that the only output I get from the checkboxes is "array". I have spent a couple hours googling like a mad man, and have found numerous tutorials on how to create checkboxes but none really cover what to do with the data once it is entered.
Here is the checkbox code:
$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' => 开发者_C百科39
);
I've set a variable for the array
$products = $form_state['values']['products'];
And the code for the email body:
$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;
Thanks for whatever assistance you can provide.
$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
精彩评论