Skip to content
Janko Marohnić edited this page Oct 15, 2022 · 1 revision

When visiting an email link for verifying account or login change, the user is typically presented with a blank form with only a submit button. If you would like to eliminate the additional click the user needs to do to confirm the action, you can hide the form, and autosubmit it on render using JavaScript.

This is how you could implement it using Stimulus:

<!-- app/views/rodauth/verify_account.html.erb -->
<%= form_with url: rodauth.verify_account_path, method: :post, data: { turbo: false, controller: "submit" }, class: "d-none" do |form| %>
  <!-- ... -->
<% end %>
// app/javascript/controllers/submit_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  connect() {
    this.element.requestSubmit()
  }
}

You can do the same for the logout form, though for that one you can also generate a POST form or link upfront.

Clone this wiki locally