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

Comments

jmcclelland created an issue. See original summary.

jmcclelland’s picture

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.

karing’s picture

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.

m_hobby’s picture

Can confirm this bug still exists and can replicate with the steps described.
In case other people find this edge case, it is possible to sidestep the bug and keep the select widget.
Simply add a page break after the existing contact field and place the file upload on the next page.
The field value is properly stored in the form data and can then accept the file upload.
Hope there is a fix for this at some point.

jitendrapurohit’s picture

Status: Active » Needs review

I've raised a PR here: https://github.com/colemanw/webform_civicrm/pull/1095

Could anyone please confirm if this fixes the error for you?

Thanks.

  • jitendrapurohit authored ef609a6e on 6.x
    Issue#3533734: Using Exiting Contact + Select list + file upload fails...
m_hobby’s picture

Hi @jitendrapurohit,
I can confirm the issue still exists on 6.3
File issues
Applying the patch fixes the issue, I can confirm I was able to upload an image and submit sucesfully.
successful upload
This is good to close, now 6.3.2 is out.

karing’s picture

Version: 6.3.0 » 6.3.2
Status: Needs review » Fixed

Thank you for testing!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.