Constructs a new up.Params instance from the given <form>.
The returned params may be passed as { params } option to
up.request() or up.render().
The params are built with the browser's own form-data algorithm, so they contain exactly what a regular form submission would send:
<input> types are supported.<input type="file"> will produce
File values.<input type="radio"> or <input type="checkbox"> is only added if it is checked.<select> adds every selected option.<fieldset disabled>, are ignored.[name] attribute are ignored.[form] attribute are included.formdata
event listener are included.[name] and [value].On top of that, elements registered as fields in
up.form.config.fieldSelectors are included. The browser cannot know about those.
Given this HTML form:
<form id="signup">
<input type="text" name="email" value="foo@bar.com">
<input type="password" name="pass" value="secret">
</form>
This serializes the form into params:
let params = up.Params.fromForm(document.querySelector('#signup'))
let email = params.get('email') // email is now 'foo@bar.com'
let pass = params.get('pass') // pass is now 'secret'
A submit button only contributes params when it is the one that submitted the form.
Pass the button as a { submitButton } option, or false to submit no button at all.
Without the option the first submit button is assumed, which is also what a browser
does when the user submits from a field by pressing Enter.
The button must belong to the form. Like the browser's FormData, up.Params.fromForm() throws
an error for a button of another form.
Like in a browser submission, a disabled field contributes no params.
The exceptions are fields and buttons that a preview disabled while a request is loading,
e.g. with [up-disable]. These still count as part of the form,
so a second submission sends the same params as the first one.
The submit button that submitted the form.
The button must belong to the form, or an error is thrown.
Pass false to include no submit button.
Tip Your coding agent can search these docs locally with the Unpoly agent skill