---
area: "Learn"
parent: "Forms chapter"
url: "https://unpoly.com/learn/handling-all-forms"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [Forms chapter](https://unpoly.com/learn/forms.md)</nav>

# Handling all forms

You can configure Unpoly to handle every form on the page, without annotating each form with an [`[up-submit]`](https://unpoly.com/api/up-submit.md) attribute.

Submissions then update fragments instead of loading full pages, and you need fewer `[up-...]` attributes in your HTML.

> #### Note
>
> Links can be handled the same way. See [Handling all links](https://unpoly.com/learn/handling-all-links.md).

<nav aria-label="Contents">

#### Contents

- [Submitting all forms](#submitting-all-forms)
- [Making exceptions](#exceptions)
- [Using a macro instead](#macro)

</nav>

## Submitting all forms {#submitting-all-forms}

To submit _all_ forms on a page without requiring an [`[up-submit]`](https://unpoly.com/api/up-submit.md) attribute:

```js
up.form.config.submitSelectors.push('form')
```

Some forms will still submit with a full page load under this setting:

- Forms with an `[up-submit=false]` attribute.
- Forms with a [`[target]`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#target) attribute (to target an iframe or open a new browser tab).
- Forms with a cross-origin `[action]` attribute.
- Any additional exceptions configured in [`up.form.config.noSubmitSelectors`](https://unpoly.com/api/up.form.config.md#config.noSubmitSelectors).

Scripts that expect a full page load after every submission need adjusting, see [Migrating legacy JavaScripts](https://unpoly.com/learn/legacy-scripts.md).

## Making exceptions {#exceptions}

You can still make exceptions by setting an `[up-submit=false]` attribute on a form:

```html
<form method="post" action="/report" up-submit="false">
  ...
</form>
```

Submitting this form makes a full page load, as if Unpoly had not been loaded.

A single [submit button](https://unpoly.com/learn/submitting-forms.md#submit-buttons) can also opt for a full page load by setting an `[up-submit=false]` attribute on the button:

```html
<form method="post" action="/report/update">
  <button type="submit" name="command" value="save">Save report</button>
  <button type="submit" name="command" value="download" up-submit="false">Download PDF</button>
</form>
```

The form is still submitted through Unpoly when the user presses _Save report_. Only _Download PDF_ loads a full page.

## Using a macro instead {#macro}

Instead of changing [`up.form.config.submitSelectors`](https://unpoly.com/api/up.form.config.md#config.submitSelectors), you can register a [macro](https://unpoly.com/api/up.macro.md) that sets [`[up-submit]`](https://unpoly.com/api/up-submit.md) on every form:

```js
up.macro('form:not([up-submit=false])', function(form) {
  form.setAttribute('up-submit', '')
})
```

Forms with `[up-submit=false]` are left alone. The [exceptions above](#submitting-all-forms) still apply: forms with a `[target]` or a cross-origin `[action]` load a full page.

A macro can set other attributes in the same pass, like [`[up-disable]`](https://unpoly.com/api/up-submit.md#up-disable) to disable the form while it submits.

<nav aria-label="Reading order">

- [Previous: Preventing loss of unsaved changes](https://unpoly.com/learn/unsaved-changes.md)
- [Next: Custom form fields](https://unpoly.com/learn/custom-form-fields.md)

</nav>

