Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8446225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:52:23+00:00 2026-06-10T09:52:23+00:00

In an effort to have everything translateable in our website ( including the error

  • 0

In an effort to have everything translateable in our website ( including the error messages for the validations ), we switched almost all of our forms to remote forms. While this helps with the ability to translate error messages, we have encountered other problems, like:

  • if the user clicks on the submit button multiple times, the action gets called multiple times. If we have a remote form for creating a new record in the database, and assuming that the user’s data is valid, each click will add a new object ( with the exact same contents ). Is there any way of making sure that such things cannot happen?

Is there somewhere I could read about remote forms best practices? How could I handle the multiple clicks problem? Is switching all the forms to remote forms a very big mistake?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:52:25+00:00Added an answer on June 10, 2026 at 9:52 am

    The simplest solution would be to generate a token for each form. Then your create action could make sure it hasn’t been used yet and determine whether the record should be created.

    Here’s how I would go about writing this feature. Note that I haven’t actually tested this, but the concept should work.

    1.
    Inside the new action create a hash to identify the form request.

    def new
      @product = Product.new
      @form_token = session["form_token"] = SecureRandom.hex(15)
    end
    

    2.
    Add a hidden field to the form that stores the form token. This will be captured in the create action to make sure the form hasn’t been submitted before.

    <%= hidden_field_tag :form_token, @form_token %>
    

    3.
    In the create action you can make sure the form token matches between the session and params variables. This will give you a chance to see if this is the first or second submission.

    def create
      # delete the form token if it matches
      if session[:form_token] == params[:form_token]
        session[:form_token] = nil
      else
        # if it doesn't match then check if a record was created recently
        product = Product.where('created_at > ?', 3.minutes.ago).where(title: params[:product][:title]).last
    
        # if the product exists then show it
        # or just return because it is a remote form
        redirect_to product and return if product.present?
      end
    
      # normal create action here ...
    end
    

    Update: What I have described above has a name, it is called a Synchronizer (or Déjà vu) Token. As described in this article, is a proper method to prevent a double submit.

    This strategy addresses the problem of duplicate form submissions. A synchronizer token is set in a user’s session and included with each form returned to the client. When that form is submitted, the synchronizer token in the form is compared to the synchronizer token in the session. The tokens should match the first time the form is submitted. If the tokens do not match, then the form submission may be disallowed and an error returned to the user. Token mismatch may occur when the user submits a form, then clicks the Back button in the browser and attempts to resubmit the same form.

    On the other hand, if the two token values match, then we are confident that the flow of control is exactly as expected. At this point, the token value in the session is modified to a new value and the form submission is accepted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a business requirement to show a cost summary for all our projects
I have done this without much effort on T-SQL, but I want to implement
I have a console application that should do best effort logging to a database
I have a list of type IList<Effort> . The model Effort contains a float
I have put much time and effort into drawing certain 3d plots and surfaces
I have a website built in PHP 4 with a framework made by hand
Assume you have five products, and all of them use one or more of
after much time and effort I have managed to create a map with a
I have a project due soon and everything is coming together really nicely, but
I have a small program that consists of three files, all belonging to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.