---
name: "[up-submit]"
area: "API"
kind: "HTML attribute"
parent: "up.form module"
url: "https://unpoly.com/api/up-submit"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.form module](https://unpoly.com/api/up.form.md)</nav>

# [up-submit]

Submits this form via JavaScript and updates a fragment with the server response.

The server must render an element matching the [target selector](https://unpoly.com/learn/targeting-fragments.md) from the `[up-target]` attribute. A matching element in the current page is then swapped with the new element from the server response. The response may include other HTML (even an entire HTML document), but only the matching element will be updated.

<nav aria-label="Guides">

- [Learn: Submitting forms](https://unpoly.com/learn/submitting-forms.md)

</nav>

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Input validation](#input-validation)
- [Short notation](#short-notation)
- [Modifying attributes](#attributes)

</nav>

## Example {#example}

This will submit the form in-page and update a fragment matching `#success`:

```html
<form method="post" action="/users" up-submit up-target="#success">
  ...
</form>

<div id="success">
  <!-- Content will appear here -->
</div>
```

See [Submitting forms](https://unpoly.com/learn/submitting-forms.md) for elaborate examples.

## Input validation {#input-validation}

When the form could not be submitted due to invalid user input, Unpoly can re-render the form with validation errors.

See [Validating forms](https://unpoly.com/learn/validation.md) for details and examples.

## Short notation {#short-notation}

You may omit the `[up-submit]` attribute if the form has one of the following attributes:

- [`[up-target]`](#up-target)
- [`[up-layer]`](#up-layer)
- [`[up-transition]`](#up-transition)

---

## Modifying attributes {#attributes}

> #### Info
>
> Most of these attributes can also be [set on the submit button](https://unpoly.com/learn/submitting-forms.md#submit-buttons).

### Targeting {#attributes-targeting}

#### [up-target=':main'] {#up-target}

(optional)

The [target selector](https://unpoly.com/learn/targeting-fragments.md) to update for a successful form submission.

#### [up-fail-target=form] {#up-fail-target}

(optional)

The [target selector](https://unpoly.com/learn/targeting-fragments.md) to update when the server responds with an error code.

By default, error responses will update the `<form>` element itself.

See [Handling error responses](https://unpoly.com/learn/error-responses.md).

#### [up-fallback='true'] {#up-fallback}

(optional)

Specifies behavior if the [target selector](https://unpoly.com/api/up.render.md#options.target) is missing from the current page or the server response.

If set to a CSS selector, Unpoly will attempt to replace that selector instead.

If set to `true`, Unpoly will attempt to replace a [main target](https://unpoly.com/api/up-main.md) instead.

If set to `false`, Unpoly will immediately reject the render promise.

#### [up-match='region'] {#up-match}

(optional)

Controls which fragment to update when the [`[up-target]`](#up-target) selector yields multiple results.

When set to `'region'`, Unpoly will prefer to update fragments in the [region](https://unpoly.com/learn/targeting-fragments.md#ambiguous-selectors) of the [origin element](https://unpoly.com/api/up.render.md#options.origin).

If set to `'first'`, Unpoly will always update the first matching fragment.

Defaults to [`up.fragment.config.match`](https://unpoly.com/api/up.fragment.config.md#config.match), which defaults to `'region'`.

#### [up-use-hungry='true'] (Experimental) {#up-use-hungry}

(optional)

Whether [`[up-hungry]`](https://unpoly.com/api/up-hungry.md) elements outside the updated fragment will also be updated.

### Navigation {#attributes-navigation}

#### [up-navigate='true'] {#up-navigate}

(optional)

Whether this fragment update is considered [navigation](https://unpoly.com/learn/navigation-defaults.md).

Setting this to `false` will disable most defaults documented below, causing Unpoly to render a fragment without side-effects like updating history or scrolling.

### Request {#attributes-request}

#### action {#action}

(required)

Where to send the form data when the form is submitted.

#### method {#method}

(required)

The HTTP method to use for the request.

The value is case-insensitive.

You can also use methods that would not be allowed on a `<form>` element, such as `'patch'` or `'delete'`. These will be [wrapped in a POST request](https://unpoly.com/api/up.network.config.md#config.wrapMethod).

#### [up-params] {#up-params}

(optional)

Additional [Form parameters](https://unpoly.com/api/up.Params.md) that should be sent as the request's [query string](https://en.wikipedia.org/wiki/Query_string) or payload.

The given value will be added to params [parsed](https://unpoly.com/api/up.Params.fromForm.md) from the form's input fields. If a param with the same name already existed in the form, it will be deleted and overridden with the given value.

#### [up-headers] {#up-headers}

(optional)

A [relaxed JSON](https://unpoly.com/api/relaxed-json.md) object with additional request headers.

Unpoly will by default send a number of custom request headers. For example, the [`X-Up-Target`](https://unpoly.com/api/X-Up-Target.md) header includes the [target selector](https://unpoly.com/learn/targeting-fragments.md). See [`up.protocol`](https://unpoly.com/api/up.protocol.md) for details.

#### [up-abort='target'] {#up-abort}

(optional)

Whether to [abort existing requests](https://unpoly.com/learn/aborting-requests.md) before rendering.

#### [up-abortable='true'] {#up-abortable}

(optional)

Whether this request may be aborted by other requests targeting the same fragments or layer.

See [aborting requests](https://unpoly.com/learn/aborting-requests.md) for details.

#### [up-background='false'] {#up-background}

(optional)

Whether this request will load in the background.

Background requests are deprioritized and won't show the [progress bar](https://unpoly.com/learn/progress-bar.md). See [Background requests](https://unpoly.com/learn/background-requests.md).

#### [up-late-delay] {#up-late-delay}

(optional)

The number of milliseconds after which this request can cause an [`up:network:late`](https://unpoly.com/api/up:network:late.md) event.

Defaults to [`up.network.config.lateDelay`](https://unpoly.com/api/up.network.config.md#config.lateDelay).

#### [up-timeout] {#up-timeout}

(optional)

The number of milliseconds after which this request fails with a timeout.

Defaults to [`up.network.config.timeout`](https://unpoly.com/api/up.network.config.md#config.timeout).

### Layer {#attributes-layer}

#### [up-layer='origin, current'] {#up-layer}

(optional)

The [layer](https://unpoly.com/api/up.layer.md) in which to match and render the fragment.

See [layer option](https://unpoly.com/learn/targeting-other-layers.md) for a list of allowed values.

To [open the fragment in a new overlay](https://unpoly.com/learn/opening-overlays.md), pass [`[up-layer=new]`](https://unpoly.com/api/up-layer-new.md). In this case attributes for [`[up-layer=new]`](https://unpoly.com/api/up-layer-new.md) may also be used.

#### [up-fail-layer='origin, current'] {#up-fail-layer}

(optional)

The [layer](https://unpoly.com/api/up.layer.md) in which to render if the server responds with an error code.

See [Rendering error responses differently](https://unpoly.com/learn/error-responses.md#fail-options).

#### [up-peel='dismiss'] {#up-peel}

(optional)

Whether to close overlays obstructing the target layer, when [updating a background layer from an overlay](https://unpoly.com/learn/closing-overlays.md#peeling).

By default, obstructing overlays will be [dismissed](https://unpoly.com/learn/closing-overlays.md#intents).
To [accept](https://unpoly.com/learn/closing-overlays.md#intents) them instead, set `[up-peel="accept"]`.
To not peel, set `[up-peel="false"]`.

### History {#attributes-history}

#### [up-history='auto'] {#up-history}

(optional)

Whether the browser URL, window title and meta tags will be [updated](https://unpoly.com/learn/updating-history.md).

If set to `true`, the history will always be updated, using the title and URL from the server response, or from given `[up-title]` and `[up-location]` attributes.

If set to `auto`, history will be updated if the `[up-target]` matches a selector in [`up.fragment.config.autoHistoryTargets`](https://unpoly.com/api/up.fragment.config.md#config.autoHistoryTargets). By default this contains all [main targets](https://unpoly.com/api/up-main.md).

If set to `false`, the history will remain unchanged.

See [Updating history](https://unpoly.com/learn/updating-history.md).

#### [up-fail-history='auto'] {#up-fail-history}

(optional)

Whether to update history when the server responds with an error code.

See [Rendering error responses differently](https://unpoly.com/learn/error-responses.md#fail-options).

#### [up-title] {#up-title}

(optional)

An explicit document title to set before rendering.

By default the title is extracted from the response's `<title>` tag. To prevent the title from being updated, set `[up-title=false]`.

This attribute is only used when [updating history](#up-history).

#### [up-location] {#up-location}

(optional)

An explicit URL to set before rendering.

By default Unpoly will use the link's `[href]` or the final URL after the server redirected. To prevent the URL from being updated, set `[up-location=false]`.

This attribute is only used when [updating history](#up-history).

#### [up-meta-tags] {#up-meta-tags}

(optional)

Whether to update [meta tags](https://unpoly.com/api/up-meta.md) in the `<head>`.

By default Unpoly will extract meta tags from the response's `<head>`. To prevent meta tags from being updated, set `[up-meta-tags=false]`.

This attribute is only used when [updating history](#up-history).

#### [up-lang] {#up-lang}

(optional)

An explicit language code to set as the [`html[lang]`](https://www.tpgi.com/using-the-html-lang-attribute/) attribute.

By default Unpoly will extract the language from the response and update the `html[lang]` attribute in the current page. To prevent the attribute from being changed, set `[up-lang=false]`.

This attribute is only used when [updating history](#up-history).

### Animation {#attributes-animation}

#### [up-transition] {#up-transition}

(optional)

The name of a [transition](https://unpoly.com/api/up.motion.md) to morph between the old and new fragment.

If you are [prepending or appending content](https://unpoly.com/learn/targeting-fragments.md#appending-or-prepending), use the `[up-animation]` attribute instead.

#### [up-animation] {#up-animation}

(optional)

The name of an [animation](https://unpoly.com/learn/animations.md) to play on the new content when [prepending or appending content](https://unpoly.com/learn/targeting-fragments.md#appending-or-prepending).

If you are replacing content (the default), use the [`[up-transition]`](https://unpoly.com/api/up-transition.md) attribute instead.

#### [up-duration] {#up-duration}

(optional)

The duration of the transition or animation (in milliseconds).

#### [up-easing] {#up-easing}

(optional)

The timing function that accelerates the transition or animation.

See [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function) for a list of available timing functions.

### Caching {#attributes-caching}

#### [up-cache='auto'] {#up-cache}

(optional)

Whether to read from and write to the [cache](https://unpoly.com/learn/caching.md).

With `[up-cache=true]` Unpoly will try to re-use a cached response before connecting to the network. To prevent display of stale content, cached responses are [reloaded once rendered](#up-revalidate). If no cached response exists, Unpoly will make a request and cache the server response.

With `[up-cache=auto]` Unpoly will use the cache only if [`up.network.config.autoCache`](https://unpoly.com/api/up.network.config.md#config.autoCache) returns `true` for the request. By default this only caches `GET` requests.

With `[up-cache=false]` Unpoly will always make a network request.

#### [up-revalidate='auto'] {#up-revalidate}

(optional)

Whether to [reload the targeted fragment](https://unpoly.com/learn/caching.md#revalidation) after it was rendered from a cached response.

With `[up-revalidate='auto']`, Unpoly will revalidate [expired](https://unpoly.com/learn/caching.md#expiration) responses. This behavior can be configured with [`up.fragment.config.autoRevalidate(response)`](https://unpoly.com/api/up.fragment.config.md#config.autoRevalidate).

With `[up-revalidate='true']`, Unpoly will always revalidate cached content, regardless of its age.

With `[up-revalidate='false']`, Unpoly will never revalidate cached content.

#### [up-revalidate-preview] (Experimental) {#up-revalidate-preview}

(optional)

The name of a [preview](https://unpoly.com/learn/previews.md) that runs while [revalidating cached content](https://unpoly.com/learn/caching.md#revalidation).

#### [up-expire-cache] {#up-expire-cache}

(optional)

Whether existing [cache](https://unpoly.com/learn/caching.md) entries will be [expired](https://unpoly.com/learn/caching.md#expiration) when this request is sent.

By default a non-GET request will expire the entire cache. Set `[up-expire-cache="false"]` to not expire any cache entries. You may also pass a [URL pattern](https://unpoly.com/api/url-patterns.md) to only expire matching requests.

Also see [`up.request({ expireCache })`](https://unpoly.com/api/up.request.md#options.expireCache) and [`up.network.config.expireCache`](https://unpoly.com/api/up.network.config.md#config.expireCache).

#### [up-evict-cache] {#up-evict-cache}

(optional)

Whether existing [cache](https://unpoly.com/learn/caching.md) entries will be [evicted](https://unpoly.com/learn/caching.md#eviction) when this request is sent.

By default no cache entries are evicted. You may also pass a [URL pattern](https://unpoly.com/api/url-patterns.md) to only evict matching requests.

Also see [`up.request({ evictCache })`](https://unpoly.com/api/up.request.md#options.evictCache) and [`up.network.config.evictCache`](https://unpoly.com/api/up.network.config.md#config.evictCache).

### Scrolling {#attributes-scrolling}

#### [up-scroll='auto'] {#up-scroll}

(optional)

How to scroll after the new fragment was rendered.

See [Scrolling](https://unpoly.com/learn/scrolling.md) for a list of allowed values.

#### [up-fail-scroll='auto'] {#up-fail-scroll}

(optional)

How to scroll after the new fragment was rendered from an error response.

See [Rendering error responses differently](https://unpoly.com/learn/error-responses.md#fail-options).

#### [up-scroll-map] {#up-scroll-map}

(optional)

A [relaxed JSON](https://unpoly.com/api/relaxed-json.md) object mapping fragment selectors to a [scrolling option](https://unpoly.com/learn/scrolling.md).

When a scroll map is given, the [`[up-scroll]`](#up-scroll) attribute is ignored.

See [Scrolling multiple viewports](https://unpoly.com/learn/scrolling.md#multiple-viewports) for examples.

#### [up-scroll-behavior='instant'] {#up-scroll-behavior}

(optional)

Whether to [animate the scroll motion](https://unpoly.com/learn/scroll-tuning.md#animating-the-scroll-motion).

#### [up-reveal-snap] {#up-reveal-snap}

(optional)

When to [snap to the top](https://unpoly.com/learn/scroll-tuning.md#snapping-to-the-screen-edge) when scrolling to an element near the top edge of the viewport's scroll buffer.

#### [up-reveal-top] {#up-reveal-top}

(optional)

When to [move a revealed element to the top](https://unpoly.com/learn/scroll-tuning.md#moving-revealed-elements-to-the-top) when scrolling to an element.

#### [up-reveal-padding] {#up-reveal-padding}

(optional)

How much [space to leave to the closest viewport edge](https://unpoly.com/learn/scroll-tuning.md#revealing-with-padding) when scrolling to an element.

#### [up-reveal-max] {#up-reveal-max}

(optional)

How many pixel lines of a [tall element to reveal](https://unpoly.com/learn/scroll-tuning.md#revealing-large-elements) when scrolling to an element.

#### [up-save-scroll='true'] {#up-save-scroll}

(optional)

Whether to [save scroll positions](https://unpoly.com/api/up.viewport.saveScroll.md) before updating the fragment.

Saved scroll positions can later be restored with [`[up-scroll=restore]`](https://unpoly.com/learn/scrolling.md#restore).

### Focus {#attributes-focus}

#### [up-focus='auto'] {#up-focus}

(optional)

What to focus after the new fragment was rendered.

See [Controlling focus](https://unpoly.com/learn/focus.md) for a list of allowed values.

#### [up-fail-focus='auto'] {#up-fail-focus}

(optional)

What to focus after the new fragment was rendered from an error response.

See [Rendering error responses differently](https://unpoly.com/learn/error-responses.md#fail-options).

#### [up-focus-visible='auto'] {#up-focus-visible}

(optional)

Whether the focused element should have a [visible focus ring](https://unpoly.com/learn/focus-visibility.md).

By default focus will be visible if [`up.viewport.config.autoFocusVisible()`](https://unpoly.com/api/up.viewport.config.md#config.autoFocusVisible) returns `true` for the focused element and [current input device](https://unpoly.com/api/up.event.inputDevice.md).

#### [up-save-focus='true'] {#up-save-focus}

(optional)

Whether to [save focus-related state](https://unpoly.com/api/up.viewport.saveFocus.md) before updating the fragment.

Saved focus state can later be restored with [`[up-focus=restore]`](https://unpoly.com/learn/focus.md#restore).

### Loading state {#attributes-loading-state}

#### [up-disable] {#up-disable}

(optional)

[Disables form controls](https://unpoly.com/learn/disabling-forms.md) while the request is loading.

The values of disabled fields will still be included in the submitted form params.

#### [up-placeholder] (Experimental) {#up-placeholder}

(optional)

A [placeholder](https://unpoly.com/learn/placeholders.md) to show in the targeted fragment while new content is loading.

Existing children of the targeted fragment [will be hidden](https://unpoly.com/learn/placeholders.md#basic-example) during the request. When the request ends for any reason, all changes will be reverted.

You can either [pass a HTML string](https://unpoly.com/learn/placeholders.md#basic-example) or [refer to a template](https://unpoly.com/learn/placeholders.md#from-template), optionally with [variables](https://unpoly.com/learn/placeholders.md#dynamic-templates).

If this link [opens a new overlay](https://unpoly.com/learn/opening-overlays.md), the placeholder will be shown in a temporary overlay with the same [visual style](https://unpoly.com/learn/customizing-overlays.md) and open animation.

#### [up-preview] {#up-preview}

(optional)

The name of a [preview](https://unpoly.com/learn/previews.md) that temporarily changes the page while new content is loading.

The preview changes will be reverted automatically when the request ends for [any reason](https://unpoly.com/learn/previews.md#ending).

#### [up-feedback='true'] {#up-feedback}

(optional)

Whether to set [feedback classes](https://unpoly.com/learn/feedback-classes.md) while loading content.

### Client state {#attributes-client-state}

#### [up-use-data] {#up-use-data}

(optional)

A [relaxed JSON](https://unpoly.com/api/relaxed-json.md) object that [overrides properties](https://unpoly.com/learn/data.md#override) from the new fragment's [data](https://unpoly.com/learn/data.md).

When updating [multiple fragments](https://unpoly.com/learn/targeting-fragments.md#multiple), `{ data }` is only applied to the primary fragment. To apply data to multiple fragments, set [`[up-use-data-map]`](#up-use-data-map).

#### [up-use-data-map] (Experimental) {#up-use-data-map}

(optional)

A [relaxed JSON](https://unpoly.com/api/relaxed-json.md) object mapping selectors to [data objects](https://unpoly.com/learn/data.md).

When a selector matches any element within an updated fragment, the matching element is compiled with the mapped data.

See [Mapping selectors to data](https://unpoly.com/learn/data.md#map).

#### [up-use-keep='true'] (Experimental) {#up-use-keep}

(optional)

Whether [`[up-keep]`](https://unpoly.com/api/up-keep.md) elements will be kept in the updated fragments.

#### [up-context] (Experimental) {#up-context}

(optional)

A [relaxed JSON](https://unpoly.com/api/relaxed-json.md) object that will be merged into the [context](https://unpoly.com/learn/layer-context.md) of the current layer once the fragment is rendered.

### Lifecycle hooks {#attributes-lifecycle-hooks}

#### [up-confirm] {#up-confirm}

(optional)

A message the user needs to confirm before any request or changes are made.

The message will be shown as a [native confirmation dialog](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm).

If the user does not confirm, no request is sent and no fragments are updated.

The message may also be passed as a `[data-confirm]` attribute, as rendered by Rails helpers like `link_to` or `button_to`.

See [Confirmation dialogs](https://unpoly.com/learn/confirmation-dialogs.md), also for showing a styled dialog instead of the browser's.

#### [up-on-loaded] {#up-on-loaded}

(optional)

A JavaScript snippet that is executed when the server responds with new HTML, but before the HTML is rendered.

The snippet runs in the following scope:

| Expression | Value |
| --- | --- |
| `this` | The link being followed |
| `event` | A preventable [`up:fragment:loaded`](https://unpoly.com/api/up:fragment:loaded.md) event |

The snippet will also run for [error responses](https://unpoly.com/learn/error-responses.md).

#### [up-on-offline] {#up-on-offline}

(optional)

A JavaScript snippet that is executed when the fragment could not be loaded due to a [disconnect or timeout](https://unpoly.com/learn/network-issues.md).

The snippet runs in the following scope:

| Expression | Value |
| --- | --- |
| `this` | The link being followed |
| `event` | An [`up:fragment:offline`](https://unpoly.com/api/up:fragment:offline.md) event |

To try again, call `event.retry()`.

#### [up-on-rendered] {#up-on-rendered}

(optional)

A JavaScript snippet that is executed when Unpoly has updated fragments.

The snippet runs in the following scope:

| Expression | Value |
| --- | --- |
| `this` | The link being followed |
| `result` | The [`up.RenderResult`](https://unpoly.com/api/up.RenderResult.md) for the respective render pass |

The snippet will be called zero, one or two times:

- When the server rendered an [empty response](https://unpoly.com/learn/conditional-requests.md#rendering-nothing), no fragments are updated. `[up-on-rendered]` is not called.
- When the server rendered a matching fragment, it will be updated on the page. `[up-on-rendered]` is called with the [result](https://unpoly.com/api/up.RenderResult.md).
- When [revalidation](https://unpoly.com/learn/caching.md#revalidation) renders a second time, `[up-on-rendered]` is called again with the final result.

Also see [Running code after rendering](https://unpoly.com/learn/render-lifecycle.md#running-code-after-rendering).

#### [up-on-finished] {#up-on-finished}

(optional)

A JavaScript snippet that is executed when no further DOM changes will be caused by this render pass.

The following state is considered "finished":

- [Animations](https://unpoly.com/api/up.motion.md) have concluded and [transitioned](https://unpoly.com/api/up-transition.md) elements have been removed from the DOM tree.
- [Async compilers](https://unpoly.com/api/up.compiler.md#async) have settled.
- [Cached content](https://unpoly.com/learn/caching.md) has been [revalidated with the server](https://unpoly.com/learn/caching.md#revalidation).
  If the server has responded with fresher content, that content has also been rendered.

The snippet runs in the following scope:

| Expression | Value |
| --- | --- |
| `this` | The link being followed |
| `result` | The [`up.RenderResult`](https://unpoly.com/api/up.RenderResult.md) for the last render pass that updated a fragment |

If [revalidation](https://unpoly.com/learn/caching.md#revalidation) re-rendered the fragment, `result` describes updates from the second render pass. If no revalidation was performed, or if revalidation yielded an [empty response](https://unpoly.com/learn/caching.md#when-nothing-changed), it is the result from the initial render pass.

To run a snippet after an [error response](https://unpoly.com/learn/error-responses.md) has finished rendering, set an `[up-on-fail-finished]` attribute instead.

Also see [Awaiting post-processing](https://unpoly.com/learn/render-lifecycle.md#postprocessing).

#### [up-on-error] {#up-on-error}

(optional)

A JavaScript snippet that is run when any error is thrown during the rendering process.

| Expression | Value |
| --- | --- |
| `this` | The link being followed |
| `error` | An [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object |

The callback is also called when the render pass fails due to [network issues](https://unpoly.com/learn/network-issues.md) or [aborts](https://unpoly.com/learn/aborting-requests.md).

Also see [Handling errors](https://unpoly.com/learn/render-lifecycle.md#handling-errors).

