I have a view that has three expose filters (Manufacturer, Type, Model), three options list (term reference to Printer vocabulary) .
Vocabulary: Printer (3 levels)
-- HP
---- xxx
------ xxxx
-- Apple
---- xxxx
------ xxxxxx
-- Dell
---- xxxx
------- xxxxx
-- ...
-- ...
(thousands of terms)
Since Form API AJAX doesn't work on views expose form, I am unable to make the them dependent select for exposed form fields. So I used jQuery to make the exposed form fields "dependent select / cascading select".
Basically, I empty all the options in views_exposed_form_alter() firstly:
$form['manufacturer_id']['#options'] = $form['type_id']['#options'] = $form['model_id']['#options'] = array();
then populate the option lists with my jQuery code accordingly.
However I get "An illegal choice has been detected." on page load, and form submit. Form submission is prevented due to Drupal form validation mechanism .
It's the form validation detect the options generated by jQuery are not come with the original form data, as I removed the options in form alter. Value of a select box is not present in its defined options .
So I tried to remove form validation in form alter as:
unset($form['#validate']);
still doesn't work, the illegal choice error remains.
============ UPDATED =================
Inspired by @kiamlaluno 's answer below, the only solution I came up is hack/patch the core. Here is what I done:
Edited /includes/form.inc
: (line 2014)
I removed the code:
$element['#needs_validation'] = TRUE;
and added:
// if not these fields, mark for validation as usual.
// so if are these fields, validation will be passed.
if ($element['#name'] != 'manufacturer_id' &&
$element['#name'] != 'type_id' &&
$element['#name'] != 'model_id' ) {
$element['#needs_validation'] = TRUE;
}
It works, the exposed form select option bypassed the validation.
But my solution is very ugly which modified the core.
I wonder if there is any other solution without touching the core? How can I bypass the validation of these exposed form fields?
Thanks!