If u have ever tried  to use ajax to load dynamic options in select field (dropdown, checkbox, radio) in drupal form. You must have seen this error.

Error : An illegal choice has been detected. Please contact the site administrator.

All you have to do to solve this problem is to bypass the validation for the field.

'#validate' => true

this will bypass the core's validation on the field and lets you choose any value in the field other than you have used as key value pair in backend.

 Using Auto load on scroll of table select will give same error. '#validate' => true doesnt solve the problem here. If anyone has done auto load of table select rows with ajax and made the bulk operations work please help me.



  1. In 7 its actually "#validated" => TRUE,

    And you’d put it in your form elements definition in your module, EG:

    function module_form_name($form,&$form_state){
    $form['name_of_element'] = array(
    '#type' => 'select',
    '#options' => array(), // Note, no options here, element will be empty
    '#validated' => TRUE, // But we accept any value

    //Now, submitting the form will allow ANY value to be in:
    function module_form_name_validate($form, &$form_state){
    $var = $form_state['values']['name_of_element']; // Anything, instead of the NULL you had defined. Allows you to populate the select element options dynamically etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.