Problem/Motivation
I receive an "'Unable to finish subscription. Please contact website support.'" error when adding a sign up on a form where a default list is configured but no other list is shown.
Steps to reproduce
- Install the module and configure API url and key.
- Add a Simple Sign up block to a page
- In the Simple Sign up configuration chose a default contact list.
- Do not select "Show" on any other list (we don't want to give the user the option of signing up to any list other than the default).
- Save the block
- Attempt to sign up.
Proposed resolution
Alter the code block in SubscribeForm.php:
// Check if all API call were successful.
if (!$activecampaign_contact_id || empty($is_in_default_contact_list) || empty($is_in_selected_contact_list)) {
$this->messenger()->addError(
$config['failed_message']
?? $this->t('Unable to finish subscription. Please contact website support.')
);
}
This conditional will always return false in this scenario, as
$is_in_selected_contact_list
will always be empty, as there is no selected contact list.
This conditional should only fail when
$is_in_selected_contact_list
is empty AND a contact list was selected in the sign up form.
Suggest the conditional is changed to:
// Check if all API call were successful.
if (!$activecampaign_contact_id || empty($is_in_default_contact_list) || (!$form_state->isValueEmpty('contact_list') && empty($is_in_selected_contact_list))) {
// ...
}