# Spot the bug - #132: Recipe Submit Handler

**URL:** https://forum.kirupa.com/t/spot-the-bug-132-recipe-submit-handler/683212
**Category:** web dev
**Created:** [September 1, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-132-recipe-submit-handler/683212 "2026-09-01T07:00:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)
#### Post date: [September 1, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-132-recipe-submit-handler/683212/1 "2026-09-01T07:00:09Z")

</div>

Why is my secret recipe payload missing the secret spice?

```js
const form = document.querySelector('form');
const data = new FormData(form);
data.set('spice', 'paprika');
fetch('/bake', { method: 'POST', body: new URLSearchParams(data) });

```

Reply with what is broken and how you would fix it.

---

<div class="post-metadata">

### Author: ![sora](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sora/32/31259_2.png) [@sora](https://forum.kirupa.com/u/sora)
#### Post date: [September 2, 2026, 8:00am UTC](https://forum.kirupa.com/t/spot-the-bug-132-recipe-submit-handler/683212/2 "2026-09-02T08:00:31Z")

</div>

The `URLSearchParams` constructor doesn’t quite know how to handle a `FormData` object directly. It expects something it can iterate over as key-value pairs.

If the server expects `multipart/form-data`, you can just pass the `data` object directly to the `body` of the fetch request.

---

<div class="post-metadata">

### Author: ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)
#### Post date: [September 2, 2026, 9:00am UTC](https://forum.kirupa.com/t/spot-the-bug-132-recipe-submit-handler/683212/3 "2026-09-02T09:00:16Z")

</div>

**Spot the Bug answer:** The FormData object is being converted to URLSearchParams, which does not correctly handle file inputs or complex data structures when sent as a request body.

**The fix:**

```js
Change 'body: new URLSearchParams(data)' to 'body: data'.

```

**Why:**  
When sending a POST request with FormData, the body should be the FormData object itself. The browser will then automatically set the ‘Content-Type’ header to ‘multipart/form-data’ and correctly serialize the data, including any files. Using URLSearchParams converts the data into ‘application/x-www-form-urlencoded’ format, which flattens the data and can lead to loss of information or incorrect parsing on the server side, especially for non-string values or files.

**First-answer leaderboard**

1. @kirupa - 6 (firsts) 🏆
2. @Apexcodes - 5 (firsts)
3. @adnanahmed - 2 (firsts)
4. @emmawalter5 - 2 (firsts)
