Problem/Motivation

This issues described two (related) issues:

  1. Filling out a form with input fields for country, state/province and district/country throws an error if only country and state/province are filled out.
  2. Filling out a form with input fields for country, state/province and email throws an error.

Detailed steps to reproduce (issue 1)

Configure form

  1. CiviCRM → Check Enable CiviCRM Processing
  2. Number of Contacts: 1
  3. 1. Contact 1? → Number of Address Fields: 1
  4. Address 1 (Primary) → Choose Country, State/Province and District/County

Fill form

  1. Country: Malaysia
  2. State/Province: Selangor
  3. District/County: - First Choose a State -
  4. Submit

Receive error inside logs

  • Location: https://<domain>/webform-civicrm/js/county/10-1131
  • Message: CiviCRM_API3_Exception: Expected one StateProvince but found 0 in civicrm_api3() (line 134 of /var/www/<domain>/vendor/civicrm/civicrm-core/api/api.php).
  • Severity: Error

Detailed steps to reproduce (issue 2)

Configure form

  1. CiviCRM → Check Enable CiviCRM Processing
  2. Number of Contacts: 1
  3. 1. Contact 1? → Number of Address Fields: 1
  4. Address 1 (Primary) → Choose Country and State/Province
  5. 1. Contact 1? → Number of Email Fields: 1

Fill form

  1. Country: Malaysia
  2. State/Province: Selangor
  3. Email: anything, e.g. test@invalid
  4. Submit

Receive errors

Forms dooes not show a submission message, but only says "The website encountered an unexpected error. Please try again later.".

The following errors appear in the log:

Error 1

  • Type: webform_submission
  • Message: CiviCRM_API3_Exception: Expected one StateProvince but found 0 in civicrm_api3() (line 134 of /var/www/<domain>/vendor/civicrm/civicrm-core/api/api.php).
  • Severity: Error

Error 2

  • Type: php
  • Message: Drupal\Core\Entity\EntityStorageException: Expected one StateProvince but found 0 in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 810 of /var/www/<domain>/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
  • Severity: Error

Proposed resolution

Do not throw an error.

Comments

fkohrt created an issue. See original summary.

fkohrt’s picture

Issue summary: View changes
fkohrt’s picture

Issue summary: View changes
fkohrt’s picture

Issue summary: View changes
fkohrt’s picture

Title: Address without district/county throws error » Addresses with state/province throw error
fkohrt’s picture

Title: Addresses with state/province throw error » Form with Address containing state/province throws error
karing’s picture

Assigned: Unassigned » jitendrapurohit
jitendrapurohit’s picture

Status: Active » Needs review

@fkohrt I've submitted a patch at https://github.com/colemanw/webform_civicrm/pull/612. Can you pls confirm if it fixes the above problem?

Thanks.

karing’s picture

Hi Florian - can you please test/confirm ->we believe this fixes the issue.
https://github.com/colemanw/webform_civicrm/pull/612

Thank you 👏 for being a sponsor of the module!

fkohrt’s picture

Hi Karin and @jitendrapurohit, thanks a lot for tackling this! I can confirm the patch fixes the issue :)

karing’s picture

Version: 8.x-5.0-beta8 » 8.x-5.x-dev
Status: Needs review » Fixed

Excellent 🎉 merging and marking as fixed.

Status: Fixed » Closed (fixed)

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