How to put select option value into particular category in webform module? I am using webform module and added a select field.

My option values are


  One|Sample 1
  Two|Sample 2
  Three|Sample 3
  Four|Sample 4
  Five|Sample 5
  Six|Sample 6


But I want these three fields in a particular category named Sample list 1


  One|Sample 1
  Two|Sample 2
  Three|Sample 3


Sample List 2:


  Four|Sample 4
  Five|Sample 5
  Six|Sample 6


Note: I don't want to show it in groups &lt;>.

I want a select list which consists of Sample List 1 and Sample List 2
In a single select field I want to store both of option values into their respective select lists.
I think you want to store this a 2 separate fields however present it to the user as 1 field.

One solution would be to use hook_form_alter() to combine the 2 selects into 1, and then put the values back where it should be after the form is submitted.

For this example lets call the first select field A, and the second field B, and the new field that combines both A and B, C.

So - first combine the fields and add an additional submit handler:

function MY_MODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  if($form_id == 'webform_client_form_&lt;ADD WEBFORM ID HERE&gt;') {

    // Make a new field which will have both options. Base in on the existing
    // field A.
    $form['submitted']['field_c'] = $form['submitted']['field_a'];

    // Combine the options of field A and B for the new field.
    $form['submitted']['field_c']['#options'] = array_merge($form['submitted']['field_a']['#options'], $form['submitted']['field_b']['#options']);

    // Hide field A and field B.
    $form['submitted']['field_a']['#access'] = $form['submitted']['field_b']['#access'] = FALSE;

    // Add an additional submit handler to put the values back where they
    // should be. Add this before the existing submit handler so we can make
    // our changes before anything is saved.
    array_unshift($form['#submit'], 'split_combined_select_values_out');

    // Add a validate function to make sure only 1 option is selected from each category
    $form['#validate'][] = 'combined_select_validate';

  }

}


In the new validation function make sure that only 1 option is selected from each category:

function combined_select_validate($form, &amp;$form_state) {

  $count_a = $count_b = 0;

  foreach($form_state['values']['submitted']['field_c'] as $val) {
    if(array_key_exists($val, $form['submitted']['field_a']['#options'])) {
      $count_a++;
    } elseif(array_key_exists($val, $form['submitted']['field_b']['#options'])) {
      $count_b++;
    }
  }

  if($count_a &gt; 1 || $count_b &gt; 1) {
    form_set_error('submitted][field_c', 'Can only select 1 option from each category');
  }

}


And then in the new submit handler put the values back where they should be:

function split_combined_select_values_out($form, &amp;$form_state) {

  foreach($form_state['values']['submitted']['field_c'] as $val) {
    // Check if the value  selected is from field A or field B
    if(array_key_exists($val, $form['submitted']['field_a']['#options'])) {
      $form_state['values']['submitted']['field_a'][$val] = $val;
    } elseif(array_key_exists($val, $form['submitted']['field_b']['#options'])) {
      $form_state['values']['submitted']['field_b'][$val] = $val;
    }
  }

  // Unset the value from field C.
  unset($form_state['values']['submitted']['field_c']);

}