From ddbb25dd00edb6c04ced054650452a7d993d5ce8 Mon Sep 17 00:00:00 2001 From: bballenn Date: Mon, 9 Apr 2018 21:24:06 +1200 Subject: [PATCH] Cast Interests to boolean value Values from an HTML form submit as string values. Casting the values to booleans fixes Mailchimp from rejecting requests as an 'Invalid Resource'. --- src/controllers/SubscribeController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/controllers/SubscribeController.php b/src/controllers/SubscribeController.php index 8d83820..d4f7893 100644 --- a/src/controllers/SubscribeController.php +++ b/src/controllers/SubscribeController.php @@ -37,13 +37,19 @@ public function actionIndex() // Fetch list id from hidden input $listId = $request->getRequiredBodyParam('listId') ? Craft::$app->security->validateData($request->post('listId')) : null; + // Cast Interests to boolean value + $interests = $request->post('interests', (object)[]); + foreach($interests as $key => $val) { + $interests[$key] = (bool)$val; + } + // Set params $params = [ 'email_address' => $request->post('email_address'), 'email_type' => $request->post('email_type', ''), 'status' => $request->getRequiredBodyParam('status') ? Craft::$app->security->validateData($request->post('status')) : 'pending', 'merge_fields' => $request->post('merge_fields', (object)[]), - 'interests' => $request->post('interests', (object)[]), + 'interests' => $interests, 'language' => $request->post('language', ''), 'vip' => $request->post('vip') ? true : false, 'location' => $request->post('location', (object)[]),