1.0 Problem/Motivation
You cannot submit a webform that has a existing contact record that is displayed as a select list when you also have a file upload.
2.0 Detailed steps to reproduce (embed screenshots)
1. Create a webform with just one contact that only includes the existing contact field
2. In the Build tab, change the "Form Widget" from "Static" to "Select List". Optionally set a CiviCRM group to limit contacts to avoid a giant list.
3. Add a file upload (it can be either a CiviCRM file upload or a Webform file upload)
4. Fill out the form
If you select a contact but do not upload a file, it works.
If you select a contact AND you upload a file, you get an error: The submitted value 97481 in the Existing Contact element is not allowed.
3.0 Proposed resolution
Still working on it.
However I have identified the problem.
1. WebformCivicrmPreProcess::alterForm
returns early when it detects that the user is uploading a file and it does not call $this->fillForm()
.
2., $this->fillForm()
is the function that loads the contact options for the existing contacts. This is not a problem immediately, but the form is cached without the options
3. In, core/lib/Drupal/Core/Form/FormBuilder::buildForm(),
if Drupal detects that the form has been cached, it uses the cached version and doesn't rebuild it from scratch.
4. When validation happens, the contact options are not present, so the form fails to validate the chosen existing contact