I inherited a website which contains a Webform made form to which I was asked to make some modifications.
The form contains two drop-down selection lists, one with predefined options, one who's content is dynamically filled in by making a request to a web-service based on the selected value of the first drop-down list.
Filling the second drop-down list is not the problem, but since it's marked as required this means that the form is also validated and that's where the error pops up: An illegal choice has been detected. Please contact the site administrator.
Now, since the content of the drop-down is dynamically generated the error itself makes sense as the selected value is compared to the available options. I want to disable the validation without removing the required flag from the form element.
I tried modifying the element options both via hook_form_alter()
and a custom validate function, various combinations and I can see that the variable is set and contains the value, yet it is still validated.
$form['submitted']['ss_function']['#needs_validation'] = FALSE;
$form['submitted']['ss_function']['#webform_validated'] = TRUE;
How can I disable the actual form validation without removing the required flag from a Webform form?