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 form[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 form[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

Return value

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