Using Exiting Contact + Select list + file upload fails

Created on 2 July 2025, 3 months ago

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

πŸ› Bug report
Status

Active

Version

6.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jmcclelland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jmcclelland
  • πŸ‡ΊπŸ‡ΈUnited States jmcclelland

    It seems that CiviCRM Options that are live options do persist in the cache, so I'm still not 100% why existing contact options do not.

  • πŸ‡¨πŸ‡¦Canada karing πŸ‡¨πŸ‡¦

    I've seen this before. We were in a crunch to get a major project onto D10 so we just worked around it by changing the existing contact element widget to Autocomplete (instead of Select). Apologies for not even documenting this...

    If you can work on a fix that would be great. I'd be happy to write a test to secure it.

Production build 0.71.5 2024