Repeated checkbox values lost when building query strings with Object.fromEntries
A common JavaScript shortcut, Object.fromEntries(new FormData(form)), can silently drop values when a form sends several entries under the same key. For example, checking both Workshop and Talk may produce only one format value because plain objects cannot hold duplicate keys. The article's example, a static HTML file, compares correct serialization with the lossy object approach. It recommends using URLSearchParams and getAll() to preserve every value, and passing the submitter to FormData so the clicked button is included. The author also advises keeping personal information out of URLs and reserving this pattern for text-only GET filters rather than file uploads.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in