Repository navigation
Releases
4.6.1
A fix release for the files in the package. No API change. jQuery 1.7.2 or later is still supported.
Fixes
src/jquery.form.jsis the classic build again, as in 4.3.0. In 4.3.0 that file was the package'smainand its only unminified classic build, so projects copy it, concatenate it or//= requireit by path. 4.4.0 replaced it with the ES module source (import jQuery from "jquery"), so a<script>tag rejected it andajaxForm()andajaxSubmit()were undefined. The 4.4.0 notes did not say so. It is now a copy ofdist/jquery.form.js, in the npm package and in the git tag that Bower, Composer and jsDelivr's/gh/URLs install from.main(dist/jquery.form.js) andmodule(dist/jquery.form.mjs) are unchanged, sorequire,importand bundlers load the same files as in 4.6.0.- cdnjs serves the classic build at
jquery.form.jsagain. cdnjs copies bothdist/andsrc/from the git tag into one folder, sohttps://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.6.0/jquery.form.jsis the ES module source. In 4.6.1 the two files are identical.jquery.form.min.js, the file the docs link, was correct in every version.
Packaging
- A bundler that imports
jquery-form/src/jquery.form.jsgets the classic build, as with 4.3.0. webpack runs its AMD branch and registers the plugin; esbuild and Vite treat it as CommonJS and get the(root, jQuery)factory without running it. Importjquery-forminstead, which loadsdist/jquery.form.mjs, as it has since 4.4.0. - The ES module sources moved to
src/esm/in the repository and are no longer in the npm package. Nothing pointed at them:moduleis the builtdist/jquery.form.mjs. If you imported a file undersrc/other thanjquery.form.js, importjquery-forminstead.
Testing
- CI now runs the suite and the end-to-end tests on jQuery 1.7.2, 1.12.4, 3.7.1, 4.0.0 and 4.1.0, in Chromium, Firefox and WebKit.
- New tests pin patterns that Drupal, Backdrop, Plone, Concrete CMS, OpenSourcePOS and Review Board rely on: a submit button set on
form.clk,extraDataadded inbeforeSend, controls changed inbeforeSerialize,ajaxSubmit(fn),formToArray(true)as$.ajaxdata, and the module build sharing the page's jQuery.
Full changelog: v4.6.0...v4.6.1
5.0.0-beta.1
5.0 is a major release with breaking changes. Read the migration guide before upgrading: each change below links to its entry, with who is affected and before and after code. With $.fn.ajaxSubmit.debug = true, the latest 4.x logs a warning for most of the features 5.0 removes. 4.x stays available (npm install jquery-form@4) and gets security fixes on a best-effort basis, with no set end date; see the security policy.
Install the beta
npm i jquery-form@nextjquery is now a peer dependency, so install it too if your project does not list it: npm i jquery@^3.7.1 jquery-form@next. The beta is on the next dist-tag; npm i jquery-form still installs 4.x. Please report problems on #629 or in a new issue. The pull request is #646.
Highlights
- Sends what a native submission sends. Fields follow tree order, only buttons, inputs, selects and textareas are sent, and image buttons,
dirname,_charset_and empty file inputs follow the HTML spec. The guide's "What your server receives" table shows each request body before and after. - A smaller, modern plugin. jQuery 3.5+ only, current browsers only, ES2020 syntax with no transpile; the jQuery < 3, Internet Explorer, Opera Presto and EdgeHTML code is gone. The minified build is 23.8 kB (9.1 kB gzip), down from 26.5 kB (10.1 kB gzip) in 4.6.0.
- An
exportsmap. Nodeimportgets the module build, bundlers get it forimportandrequire, andrequirein Node keeps the CommonJS factory. - Selector options are only selectors. A string in
target,iframeTargetorincludeHiddenis never parsed as HTML, so it can't create elements.
Breaking changes
Platform
- jQuery 3.5 or later is required, as a peer dependency.
peerDependencies: { "jquery": ">=3.5.0" }; on an older jQuery,ajaxSubmitandajaxFormthrowjquery.form 5 needs jQuery 3.5 or later; this is <version>. Tested on jQuery 3.5.0, 3.7.1 and 4.0.0. - Internet Explorer, Opera Presto and EdgeHTML are no longer supported. Current Chrome, Edge, Firefox (and ESR) and Safari; the builds need Chrome or Edge 80, Firefox 78 or Safari 14 or later. The
iframeSrcdefault isabout:blankon every page.
Packaging
- The package has an
exportsmap. Nodeimport "jquery-form"loadsdist/jquery.form.mjs(it needs a globalwindowanddocument) instead of the CommonJS factory; paths outsidedistandpackage.jsonno longer resolve. srcis no longer published. Importjquery-formorjquery-form/dist/jquery.form.mjsinstead ofjquery-form/src/....form.jquery.jsonis removed.
Removals
$.fn.attr2is removed: use.prop()or.attr().clearInputsis removed: useclearFields.closeKeepAliveis ignored.semanticis ignored: fields are always sent in tree order.delegation: truethrowsjquery.form: delegation needs a selector in 5.0, e.g. delegation: "form.ajax". Pass the selector:$(document).ajaxForm({ delegation: "form.ajax" }).ajaxFormon an empty selection before the DOM is ready no longer waits.- The iframe transport is used only with
iframe: true: uploads always useFormDataotherwise. enable()andselected()stay, unchanged.
Behavior and serialization
- Iframe
.doneand.thenreceive the parsed data, assuccessand$.ajaxdo. - Replacing
$.fieldValueno longer changes what is sent: use jQueryvalHooks. - Selector options are never parsed as HTML; a positional pseudo-class in
includeHiddentests each element alone. - Fields are sent in tree order.
- Only buttons, inputs, selects and textareas are sent.
- A clicked image button sends only its coordinates; check
name.xon the server. - A clicked image button without a name sends
xandy. - Controls with
dirnamesend their direction, on every transport, including a clicked submit input's field in iframe uploads. - A hidden
_charset_input sendsUTF-8. - An empty file input is sent as an empty file in uploads.
- Iframe uploads send the submitter at its place.
Kept on purpose (see Differences from a native submission): a selected file makes the request multipart without enctype, a GET request keeps the action's query, and a clicked submit input without a value sends an empty value.
The iframe transport: tell us if you use it
5.0 keeps the hidden-iframe upload transport, but only when you pass iframe: true; every other upload uses FormData. It may be removed in 6.0. If you use iframe: true, comment on #629 with your use case.
Docs
- A new migration guide, in the docs site menu as "Upgrading to 5.0" and linked from the README, with a "New in 5.0" section.
- The API page documents every method, including
formToArray,enable,selectedand$.fieldValue, and lists what 5.0 removes. - The options page documents
includeHidden, the iframe rejection arguments that differ from$.ajax, and the deliberate differences from a native submission. - The examples are rewritten for 5.0, with no demo server and with server snippets that escape their output. The Form Fields page shows what
fieldValueandfieldSerializereturn, and the FAQ is rewritten. SECURITY.mdsupports 5.x, with 4.x fixes on a best-effort basis.
Testing (no effect on the published files)
- The suite runs on Chromium, WebKit and Firefox with jQuery 3.5.0, 3.7.1 and 4.0.0 (1112 tests per jQuery version), at 100% coverage.
- The serialization oracle and the end-to-end tests compare with a native submission; the differences from a native submission that 5.0 removes are no longer allowed in them.
- Published-file tests check each
exportskey, Nodeimportresolving to the module build, themodulecondition, and that a deepsrcimport fails. - Every breaking change has a test that fails on 4.6.0 and an entry in the migration guide.
- The package is published from CI with npm provenance; pre-releases go to the
nextdist-tag.
4.6.0
Warning
src/jquery.form.js is an ES module in this release, not the classic build it was in 4.3.0. It also imports the other files in src/. A page or build that copies it by path and loads it as a classic script fails, and ajaxForm() and ajaxSubmit() are undefined. require("jquery-form"), import "jquery-form" and bundlers aren't affected. Update to 4.6.1, which ships the classic build at that path again, or copy dist/jquery.form.js instead. The same applies to cdnjs: https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.6.0/jquery.form.js serves this ES module, because cdnjs copies src/jquery.form.js over the classic build. Use jquery.form.min.js, which is correct, or 4.6.1.
A bug-fix release. No breaking changes are intended. Behavior changes only where the old behavior was a bug or differed from a native form submission, so read the list below if your code relied on any of them. jQuery 1.7.2 or later is still supported. Every change is tested on jQuery 1.7.2, 3.7.1 and 4.0.0, and the test suite now runs on Chromium, Firefox and WebKit.
Fixes
targetandiframeTargetstrings are looked up only as selectors. Both were passed to$(), which builds elements from a string that looks like HTML and runs any inline handlers in it. A string is now looked up with$(document).find(). A selector finds the same elements as before. A string that starts with<matches nothing (and logs a message when$.fn.ajaxSubmit.debugis on). On jQuery 1.7.2, a selector with a tag in an attribute value, such asdiv[title="<b>"], now works. Elements and jQuery objects are used as given.- A lone surrogate is sent as U+FFFD.
formSerialize,fieldSerialize,ajaxSubmitand iframe uploads threwURIErrorwhen a field name or value, or a key or string value indataorextraData, held an unpaired UTF-16 surrogate. Each one is now replaced with U+FFFD, as a native form submission andFormDatado. A stringdataoption is passed through unchanged. - Spaces encode as
+on every jQuery version. On jQuery 3 and later,formSerialize,fieldSerialize, GET query strings and urlencoded bodies wrote a space as%20, while jQuery 1 and 2 and a native form submission write+. They now write+everywhere. Servers decode both the same way; only code that compares the strings sees a difference. - An iframe response that cannot be parsed rejects with
parsererror, aserrorandcompletealready reported. When the response also carries an error status (astatusattribute outside 2xx),error,ajaxErrorand the rejection receive itsstatusText, as$.ajaxreports a server error. - An iframe upload no longer sends a clicked button that a disabled
<fieldset>disables, as the other transports and a native submission already did.
Packaging
- Bundlers get the module build. The
browserfield pointed at the minified classic build, so webpack, Vite and Browserify bundled it. It is removed: webpack and Vite usemodule(dist/jquery.form.mjs) and Browserify usesmain(dist/jquery.form.js). Newjsdelivrandunpkgfields keep a bare CDN URL servingdist/jquery.form.min.js. - The CommonJS factory uses the window it is given.
require("jquery-form")(root, $)read the globalwindowanddocument, so it threw in Node without a global DOM. It now takes them fromroot. LICENSE-MITis in the package, next toLICENSE. The license field is now the SPDX expression(LGPL-2.1-or-later OR MIT): the same terms, written the current way.- The package
homepageis the docs site, https://jquery-form.github.io/form/.
Deprecations
- Replacing
$.fieldValueto change what is serialized logs a deprecation warning once per page when$.fn.ajaxSubmit.debugis on. It still works in 4.x; 5.0 drops it, so use jQueryvalHooksinstead. - The API docs now have a Deprecations section listing every warning and its replacement.
Docs
- The README is now a short landing page: installation, usage (module import, CommonJS, script tag), file uploads, compatibility and security. The full reference is on the docs site.
- The docs site's links to old malsup.com pages point at its own pages, and its demos load over https.
- Bug reports use an issue form that asks for the plugin, jQuery and browser versions. Security reports go through
SECURITY.md.
Full changelog: v4.5.0...v4.6.0
4.5.0
Warning
src/jquery.form.js is an ES module in this release, not the classic build it was in 4.3.0. It also imports the other files in src/ now. A page or build that copies it by path and loads it as a classic script fails, and ajaxForm() and ajaxSubmit() are undefined. require("jquery-form"), import "jquery-form" and bundlers aren't affected. Fixed in 4.6.1; on this release, copy dist/jquery.form.js instead.
The plugin's source is now split into modules, and this release fixes a long list of bugs found while pinning down its behavior. No breaking changes are intended. Behavior changes only where the old behavior was a bug or differed from a native form submission, so read the lists below if your code relied on any of them. jQuery 1.7.2 or later is still supported. Every change is tested on jQuery 1.7.2, 3.7.1 and 4.0.0.
New
delegation: "<selector>"limitsajaxFormdelegation to forms that match a selector (#353).delegation: trueis unchanged, but it now logs a warning on jQuery 3 and later, where it binds every form on the page.ajaxFormUnbind()also removes delegated bindings, andajaxFormUnbind(selector)removes one of them.requestFormat: "json"sends the form as a JSON body (#545). The idea came from #557 by @zhangciwu.errorandcompleteaccept arrays of functions, as in$.ajax.ajaxSubmiton jQuery's slim build throws a clear error (#541) instead of failing later.
Deprecations
These log a warning once per page when $.fn.ajaxSubmit.debug is on, and 5.0 will remove them.
clearInputs: useclearFields.$.fn.attr2: use.prop()or.attr().ajaxFormon an empty selection before the DOM is ready, which queues the binding: call it inside$(fn), or usedelegation: "<selector>".- The iframe transport chosen automatically when the browser has no
FormData: setiframe: true. - The
closeKeepAliveoption, a workaround for Safari 3 and 4. - jQuery older than 3.5. 5.0 will need jQuery 3.5 or later.
enable and selected are kept.
Fixes: submission and transports
- Every transport uses the same request method.
methodwins overtype, and it is read afterbeforeSubmit. - A url of
falseor""submits to the form'saction. - A string
dataoption is treated as a query string. thisin callbacks is the caller'scontextobject, not a copy of it.successruns whentargetmatches nothing.beforeSendreturningfalsecancels a FormData upload, as it already did on the other transports.uploadProgresskeeps a customxhrfactory, and reports position 0 and 0% for a progress event with nothing loaded.- A multipart
enctypeis recognized regardless of case and surrounding spaces. - File uploads with GET put file names in the URL, never
[object File].
Fixes: iframe uploads
- Events fire in the same order as
$.ajax, and abeforeSendveto ends the global events withajaxStop. - Every upload settles exactly once, including when an exception is thrown.
abort()before the delayed post cancels it. - Uploads started in the same millisecond use different frames, and an
iframeTargetwithout a name receives the upload. dataTypeis read case-insensitively.- A frame that is not in the document fails with an error instead of opening a new window.
- The form's attributes are restored exactly after the upload (#380).
- With
closeKeepAlive, controls disabled inbeforeSubmitare posted and re-enabled afterwards.
Fixes: serialization, fields and form members
- Controls named like form members (
getAttribute,ownerDocument,tagName,reset,clkand others) no longer break the plugin. A control namedparentNodethrows a clear error. - The contents of a disabled
<fieldset>or<optgroup>are not sent.semantic: truesends only controls the form owns. Namedfieldset,outputandobjectelements are not sent. A lone CR in a value is sent as CRLF on every jQuery version. ajaxFormsends the browser'sSubmitEvent.submitterwhen no click was captured, for example after pressing Enter or callingrequestSubmit(button).resetFormmatches a native reset. It keeps the values of checkboxes, radios, hidden inputs and buttons, empties file inputs instead of throwing, and selects the last default option of a single select.clearFormandclearFieldscleardatetime-localinputs.
Docs
- How to sanitize a response inserted by
target, withdataFilter(jQuery 3.5 and later). - The list of options that must come only from trusted code, not from user input.
- What an iframe upload response has to look like.
Build
- The classic build runs its whole factory in strict mode. The same three
distfiles are published.
Known, not changed in 4.5.0
- String values of
targetandiframeTargetare still passed to$(), so pass only selectors from your own code (see the trusted options list). 4.6.0 will look them up only as selectors.
Full changelog: v4.4.0...v4.5.0
4.4.0
Warning
Changed in this release and not listed below: src/jquery.form.js is an ES module. In 4.3.0 it was the classic build and the package's main. Here it starts with import jQuery from "jquery", so a page or build that loads it as a classic script fails with Cannot use import statement outside a module, and ajaxForm() and ajaxSubmit() are undefined. require("jquery-form"), import "jquery-form" and bundlers aren't affected, because they go through main and module. Fixed in 4.6.1, which ships the classic build at that path again. On 4.4.0, copy dist/jquery.form.js instead.
The first release since 4.3.0 (2020). It fixes four cross-site scripting vulnerabilities, adds jQuery 4 support and a module build, and fixes several long-standing bugs. There is no API change; the changes below are the ones a page could notice. Upgrading is recommended for everyone.
Security
All four affect 4.3.0 and earlier, and are fixed in 4.4.0. CVE IDs have been requested and will be added to the advisories when assigned.
| Advisory | Severity | Affected feature |
|---|---|---|
| GHSA-x8mc-9vpg-2rc8 | Medium | The iframe upload transport (iframe: true) built HTML from field names, the clicked button's name, the csrf-param meta tag and iframeSrc |
| GHSA-8395-7m7x-q7q2 | Medium | resetForm() passed a <label>'s for attribute to $() |
| GHSA-g7mw-rwc2-4h3g | Medium | semantic: true built a selector from the form's id |
| GHSA-4w39-46xw-8jm2 | Medium | target inserted a parsed JSON response as HTML |
Thanks to Rudloff for reporting the iframe transport and resetForm() issues. The other two were found in a maintainer security review.
Hardening in the same area:
- The Rails CSRF token (
<meta name="csrf-token">) is added only to same-origin iframe uploads, and only when they post the form. A cross-origin upload no longer receives it, and a GET upload no longer puts it in the query string. - An extra field named
hasOwnPropertyno longer breaks iframe uploads.
jQuery 4 and packaging
- jQuery 4 is supported (#616). Every change is tested on jQuery 1.7.2, 3.7.1 and 4.0.0.
- A module build.
modulepoints atdist/jquery.form.mjs, which registers the plugin when imported, so bundlers such as Vite pick it up (#618).mainmoved fromsrc/jquery.form.jstodist/jquery.form.js, the classic script-tag, AMD and CommonJS build, anddist/jquery.form.min.jsis still there.src/jquery.form.jsis now the ES module source (see the warning above). - The published package is smaller. It contains
dist,src, the README and the license, without the tests and repository files. - Published with npm provenance from GitHub Actions.
dist/files no longer carry/* eslint */or/* global */comments, which applied to code concatenated after the plugin (#553).
Fixes and behavior changes
- The iframe transport builds its hidden inputs and iframe with DOM APIs. Array and object
data/extraDatavalues are sent as separate fields, as$.paramsends them, instead of"a,b"or[object Object](#597). resetForm()on a<label>resets the control itsforattribute names. This never worked before: a plain id matched nothing, and a match threw.semantic: truematchesform="…"controls by comparing the attribute, so a form id with quotes or brackets no longer throws or picks up unrelated fields.targetinserts only string responses. If jQuery has parsed the response (JSON or XML), the target is left unchanged, a message is logged underdebug, andsuccessis still called.- A
<button>without atypeattribute is captured as the submitter (#588), so its name and value are sent, as in a native submit. resetForm,clearFields,fieldValueandselectedaccept nodes without a tag name (#600).resetFormon the document resets the fields inside it.- JSON responses are parsed with
JSON.parseonly. JSON that onlyevalaccepted (single quotes, unquoted keys) now fails with a parse error instead of being evaluated. - Iframe uploads with
dataType: "script"run the response, as$.ajaxdoes. - Aborting an iframe upload rejects its Deferred with
"aborted", firesajaxCompleteandajaxStop, and removes the iframe. A second abort, or an abort after completion, does nothing. - Iframe responses that fail to parse report
parsererrorinstead ofsuccesswith no data. - FormData uploads serialize
datawith the global$.ajaxSettings.traditional, anddata: {}no longer adds a field with an empty name. - GET urls with a fragment keep the form data, placed before the fragment.
- Controls named like form properties (
elements,action,setAttribute,removeAttribute) no longer break serialization or iframe uploads.
Known, not changed in 4.4.0
- With
delegation: trueon jQuery 3 and later, the handler is not scoped to the selected forms. BindajaxFormdirectly to the forms instead. dataType: "script"on jQuery 4 deliversundefinedtosuccess, because jQuery 4 loads such requests through a script tag. The script still runs.
Full changelog: v4.3.0...v4.4.0
v4.3.0
Note
In this release src/jquery.form.js is the classic build and the package's main. In 4.4.0 through 4.6.0 that path holds the ES module source instead, which a <script> tag can't load. 4.6.1 restores the classic build there. If you copy this file by path, update to 4.6.1 or later, or copy dist/jquery.form.js, the classic build in every release from 4.4.0.
New Features
- #566 Adds beforeFormUnbind callback
Bug Fixes
- #572 Updates default iframeSrc to be 'about:blank' for browsers other than IE
v4.2.2
v4.2.1
v4.2.0
News
jQuery Form is confirmed to be compatible with jQuery 2 and 3! 🎉
If you see any incompatibilities, please report a bug or, preferrably, a pull request.
New Features
Bug Fixes
v4.1.0
New Features
- #436 Allows formToArray and ajaxSubmit to work on non-form tags
- #158 #421 #516 #517 When serializing text, encode all line breaks as CRLF pairs per the
application/x-www-form-urlencodedspecification - 76a0b2a #450 #502 Updates AMD definition and adds CommonJS support
- Moves documentation from malsup.com to GitHub Pages
- Adds automated testing using ESLint, Grunt, Mocha, Chai, and PhantomJS