Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions fern/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,15 @@ function initializeSubscribeForm() {
submitBtn.textContent = 'Submitting...';

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

fetch(formAction, {
method: 'POST',
body: formData,
body: body,
redirect: 'manual',
})
.then(function (response) {
Expand Down
4 changes: 4 additions & 0 deletions fern/custom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ assert(customJsContent.indexOf("redirect: 'manual'") !== -1,
'custom.js uses fetch with redirect:manual to handle 302');
assert(customJsContent.indexOf('opaqueredirect') !== -1,
'custom.js checks for opaqueredirect response type');
assert(customJsContent.indexOf('URLSearchParams') !== -1,
'custom.js sends body as application/x-www-form-urlencoded (URLSearchParams)');
assert(customJsContent.indexOf('new FormData()') === -1,
'custom.js does not use FormData (multipart) for the Customer.io submit');
assert(customJsContent.indexOf('subscribe-form-message') !== -1,
'custom.js updates the message div');
assert(customJsContent.indexOf('Thanks for subscribing') !== -1,
Expand Down
Loading