Edit this page

up.form up.submit(form, [options])
JavaScript function

Submits a form via AJAX and updates a page fragment with the response.

Instead of loading a new page, the form is submitted via AJAX. The response is parsed for a CSS selector and the matching elements will replace corresponding elements on the current page.

The unobtrusive variant of this is the [up-submit] selector. See its documentation to learn how form submissions work in Unpoly.

Submitting a form is considered navigation.

Emits the event up:form:submit.

Example

up.submit('form.new-user', { target: '.main' })

Parameters

form ElementorjQueryorstring

The form to submit.

If the argument points to an element that is not a form, Unpoly will search its ancestors for the closest form.

[options] Object optional

Render options that should be used for submitting the form.

Unpoly will parse render options from the given form's attributes like [up-target] or [up-transition]. See [up-submit] for a list of supported attributes.

You may pass this additional options object to supplement or override options parsed from the form attributes.

[options.navigate=true] boolean optional

Whether this fragment update is considered navigation.

Setting this to false will disable most defaults.

[options.failTarget] stringorElement optional

The target selector to update when the server responds with an error code.

Defaults to the form element itself.

See Handling failed responses.

[options.disable] booleanorstring optional

Whether to disable form controls while the form is submitting.

[options.origin] Element optional

The element that triggered the form submission.

This defaults to the first applicable:

  • An element within the form that was focused when the form was submitted (e.g. when the user presses Enter inside a text field)
  • The button clicked to submit the form.
  • The first submit button
  • The <form> element
[options.params] Objectorup.ParamsorFormDataorstringorArray optional

Additional Form parameters that should be sent as the request's query string or payload.

The given value will be added to params parsed from the form's input field.

[options.submitButton] Elementorfalse optional

The submit button used to submit the form.

By default the form's first submit button will be assumed. Pass { submitButton: false } to not assume any submit button.

Return value

A promise that fulfills with an up.RenderResult once the server response was loaded and rendered.