enter image description here

I have created content type with field as List(text). If I select any of above option and try to save it, it through "fieldName: illegal value" error.But if I modified option in below format and then try to save it. It get saved successfully.





Does list doesnot support first format? Is there any other way to resolve this without changing its format ?

  • Hi thanks for response. Yups its option group. Also attached image related to it. – Sudha Bisht Sep 14 '16 at 9:36
  • here the problem is you havent provided the key properly . So its not able to store the value or get the value – Shreya Shetty Sep 14 '16 at 9:38
  • Hi Shreya, so how should I provide key without changing format specified in image. Can you please help by giving any example. – Sudha Bisht Sep 14 '16 at 10:09

You can achieve that by using hook_form_alter function.

I've tested the following code on my instance. It's working fine.

Use the following code in your custom module.

function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {     
        if ($form['#form_id'] == 'YOUR-CONTENT-TYPE_node_form') {
         $form['YOUR-FILED-NAME']['und']['#options'] = array (
       'Group1' => array(
          1 => 'Option1',
          2 => 'Option2',

        'Group2' => array(
          3 => 'Option3',
          4 => 'Option4',
    return $form;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.