Skip to content

Commit e185035

Browse files
committed
fix: send subscribe form as urlencoded so Customer.io records form_submit
The whats-new subscribe form posts to Customer.io's submit_action endpoint, which expects application/x-www-form-urlencoded (the encoding native HTML form POSTs use). Commit 6cce858 replaced the native submit with a fetch() that sent FormData (multipart/form-data); the endpoint accepts the request and returns the 302, but does not record a form_submit event, so no one is added to the subscriber segment. The opaqueredirect response made the UI report success regardless. Switch the body to URLSearchParams so the request matches the encoding the endpoint actually processes. Add regression tests pinning the body type.
1 parent 38945b8 commit e185035

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

fern/custom.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,15 @@ function initializeSubscribeForm() {
158158
submitBtn.textContent = 'Submitting...';
159159

160160
var formAction = form.getAttribute('action');
161-
var formData = new FormData();
162-
formData.append('email', email);
161+
// Customer.io's submit_action endpoint expects application/x-www-form-urlencoded
162+
// (the encoding native HTML form POSTs use). FormData sends multipart/form-data,
163+
// which the endpoint accepts but does not record as a form_submit event.
164+
var body = new URLSearchParams();
165+
body.append('email', email);
163166

164167
fetch(formAction, {
165168
method: 'POST',
166-
body: formData,
169+
body: body,
167170
redirect: 'manual',
168171
})
169172
.then(function (response) {

fern/custom.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ assert(customJsContent.indexOf("redirect: 'manual'") !== -1,
103103
'custom.js uses fetch with redirect:manual to handle 302');
104104
assert(customJsContent.indexOf('opaqueredirect') !== -1,
105105
'custom.js checks for opaqueredirect response type');
106+
assert(customJsContent.indexOf('URLSearchParams') !== -1,
107+
'custom.js sends body as application/x-www-form-urlencoded (URLSearchParams)');
108+
assert(customJsContent.indexOf('new FormData()') === -1,
109+
'custom.js does not use FormData (multipart) for the Customer.io submit');
106110
assert(customJsContent.indexOf('subscribe-form-message') !== -1,
107111
'custom.js updates the message div');
108112
assert(customJsContent.indexOf('Thanks for subscribing') !== -1,

0 commit comments

Comments
 (0)