# How to show form validation errors?

**URL:** <https://discuss.hotwired.dev/t/how-to-show-form-validation-errors/1544>\
**Category:** General\
**Created:** [December 22, 2020, 8:39pm UTC](https://discuss.hotwired.dev/t/how-to-show-form-validation-errors/1544 "2020-12-22T20:39:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsazup](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@dsazup](https://discuss.hotwired.dev/u/dsazup)\
**Post date:** [December 22, 2020, 8:39pm UTC](https://discuss.hotwired.dev/t/how-to-show-form-validation-errors/1544/1 "2020-12-22T20:39:08Z")

</div>

I tried:

new.html.erb

```
<%= turbo_frame_tag "form" do %>
    <%= render 'form', course: @course %>
<% end %>

```

controller:

```
respond_to do |format|
      if @course.save
        format.turbo_stream { redirect_to edit_course_path(@course), notice: "Course was successfully created." }
      else
        format.turbo_stream
      end
    end

```

create.turbo\_stream.erb

```
<%= turbo_stream.replace "form" do %>
  <%= render "form.html", course: @course %>
<% end %>

```

This way, I can show form validation errors, but then if the form is successful, it doesn’t redirect properly. I.e I can actually see these two requests happening behind the scenes.

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/stimulusjs/original/2X/8/8cb119ddd09a512b7fd3d63f2a4b5f45975b5e37.png)

If I don’t wrap the form in the turbo\_frame\_tag, then redirect works, but how can I then show form errors?

Edit: thanks to [https://twitter.com/Intrepidd/status/1341482325280960519](https://twitter.com/Intrepidd/status/1341482325280960519), the key is to add frame: “\_top” to the turbo\_frame\_tag. E.g `<%= turbo_frame_tag "form", target: "_top" do %>`. Then redirects start to work.

---

<div class="post-metadata">

**Author:** ![pomartel](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/pomartel/32/1096_2.png) [@pomartel](https://discuss.hotwired.dev/u/pomartel)\
**Post date:** [December 22, 2020, 8:51pm UTC](https://discuss.hotwired.dev/t/how-to-show-form-validation-errors/1544/2 "2020-12-22T20:51:14Z")

</div>

Have you tried not wrapping the `redirect_to` in `format.turbo_stream`?

Here it says Turbo Drive expects an HTTP 303 redirect response: [https://turbo.hotwire.dev/handbook/drive#redirecting-after-a-form-submission](https://turbo.hotwire.dev/handbook/drive#redirecting-after-a-form-submission)

---

<div class="post-metadata">

**Author:** ![sam](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/sam/32/1091_2.png) [@sam](https://discuss.hotwired.dev/u/sam)\
**Post date:** [December 22, 2020, 10:52pm UTC](https://discuss.hotwired.dev/t/how-to-show-form-validation-errors/1544/3 "2020-12-22T22:52:19Z")

</div>

We intend to allow HTTP 422 responses for form submissions inside frames, but it didn’t make the cut for the initial beta release.

For now, you can try sending a Turbo Streams response that re-renders your form with errors.

---

<div class="post-metadata">

**Author:** ![danjac](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/danjac/32/1099_2.png) [@danjac](https://discuss.hotwired.dev/u/danjac)\
**Post date:** [December 23, 2020, 3:02pm UTC](https://discuss.hotwired.dev/t/how-to-show-form-validation-errors/1544/4 "2020-12-23T15:02:22Z")

</div>

Is there going to be support for adding data-turbo=“false” to forms? I have some legacy forms where I just need to handle simple form submission (full page refresh to show validation errors is fine), but Turbo Drive does not appear to allow this.

---

<div class="post-metadata">

**Author:** ![sam](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/sam/32/1091_2.png) [@sam](https://discuss.hotwired.dev/u/sam)\
**Post date:** [December 23, 2020, 3:06pm UTC](https://discuss.hotwired.dev/t/how-to-show-form-validation-errors/1544/5 "2020-12-23T15:06:19Z")

</div>

Yes, there’s a [pull request](https://github.com/hotwired/turbo/pull/3) open for this but it didn’t make the cut for the initial beta release.
