Loading a draft webform sends country_id as string instead of numeric, causing a WSOD

Created on 18 July 2024, 5 months ago
Updated 29 July 2024, 5 months ago

1.0 Problem/Motivation

On a webform when we have the 'drafts' option activated and we also expose the country field (part of the address field), on a clean (no drafts) submission everything works fine.

However, if we first save as draft our current progress and then reload the draft and submit, we get a WSOD of:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Entity\EntityStorageException: 'Azerbaijan' is not a valid option for field country_id in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 815 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

This is coming from:

Drupal\webform_civicrm\WebformCivicrmPostProcess->saveContactLocation (/webform_civicrm/src/WebformCivicrmPostProcess.php:892)

Specifically, the `$params` array, instead of holding the country ID in the `country_id` field (and as I've noticed the `state_province_id` as well), does keep the full country name instead

Please see the 2 screenshots:
* webform_civicrm_submit_address_before.jpg: Normal operation
* webform_civicrm_submit_address_after_draft.jpg: Country and province have been converted into Strings instead of numeric values

2.0 Detailed steps to reproduce (embed screenshots)

* Make sure that your contact has **no country** selected in the address (preferably an empty address). This is extremely important
* Create a new webform with 2 pages.
* Add the country field (from CiviCRM) and set the field on page 2
* Enable drafts and preview (helpful)
* Do a first run on filling in the webform and on the preview, just save the draft. Make sure that you pickup a/any country and optionally a province.
* Revisit the webform
* Select to load the draft
* Submit the form

3.0 Proposed resolution

Perhaps intercept the form submission and translate strings into numeric values??

Edit: The issue appears to be affecting also all customfields that have optionvalues attached (select lists/radios)

🐛 Bug report
Status

Active

Version

6.2

Component

CiviCRM Data Handling

Created by

🇬🇧United Kingdom vangelisp Fife, Scotland

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

Comments & Activities

Production build 0.71.5 2024