---
name: "X-Up-Fail-Target"
area: "API"
kind: "HTTP header"
parent: "up.protocol module"
url: "https://unpoly.com/api/X-Up-Fail-Target"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.protocol module](https://unpoly.com/api/up.protocol.md)</nav>

# X-Up-Fail-Target

This request header contains the [target selector](https://unpoly.com/learn/targeting-fragments.md) that Unpoly updates when the server sends an [error response](https://unpoly.com/learn/error-responses.md).

An error response has a status code other than 2xx, but still contains HTML.

Server-side code is free to [optimize its response](https://unpoly.com/learn/optimizing-responses.md) to an error response by only rendering HTML that matches the provided selector. For example, you might prefer to not render an expensive sidebar if the sidebar is not targeted.

## Example {#example}

```http
X-Up-Target: .menu
X-Up-Fail-Target: body
```

## Signaling failed form submissions {#signaling-failed-form-submissions}

When [submitting a form](https://unpoly.com/learn/submitting-forms.md), Unpoly needs to know whether the form submission has failed (to update the form with validation errors) or succeeded (to update the `[up-target]` selector).

For Unpoly to be able to detect a failed form submission, the response must return a non-2xx HTTP status code. We recommend using [HTTP 422](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422) (Unprocessable Entity).

To do so in [Ruby on Rails](http://rubyonrails.org/), pass a [`:status` option to `render`](http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option):

```ruby
class UsersController < ApplicationController

  def create
    user_params = params[:user].permit(:email, :password)
    @user = User.new(user_params)
    if @user.save
      sign_in @user
    else
      render 'form', status: :unprocessable_entity
    end
  end

end
```

The example uses Ruby on Rails, but works similarly with any other backend.

