2011-10-11 14 views
1

私は現在Drupal 6のカスタムフォームモジュールで作業しています。このフォームでは、約10種類のオプションのチェックボックスフィールドを使用しています。私が問題に思っているのは、チェックボックスから出力される唯一の出力が「配列」だということです。私は狂った男のようにグーグルグーグルで過ごしましたが、チェックボックスの作成方法に関するチュートリアルが多数見つかりましたが、一度入力したデータで何をすべきかは本当にカバーしていません。Drupal 6がチェックボックス配列からデータを引き出す

$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
$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 
+0

ありがとうございます、それは動作します – DanTheMan

関連する問題