Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prevent multiple form submissions

[#110 state:resolved]
  • Loading branch information...
commit a5d829fb1e8881e69aba6dc33957bc6d427ac722 1 parent 6b86c5d
Michael Dvorkin michaeldv authored
Showing with 35 additions and 54 deletions.
  1. +4 −0 CHANGELOG
  2. +5 −0 app/helpers/application_helper.rb
  3. +2 −2 app/views/accounts/_create.html.haml
  4. +2 −2 app/views/accounts/_edit.html.haml
  5. +1 −1  app/views/admin/users/_create.html.haml
  6. +1 −1  app/views/admin/users/_edit.html.haml
  7. +0 −13 app/views/admin/users/edit.html.haml
  8. +1 −1  app/views/authentications/new.html.haml
  9. +1 −1  app/views/campaigns/_create.html.haml
  10. +1 −1  app/views/campaigns/_edit.html.haml
  11. +1 −1  app/views/contacts/_create.html.haml
  12. +1 −1  app/views/contacts/_edit.html.haml
  13. +1 −1  app/views/leads/_convert.html.haml
  14. +1 −1  app/views/leads/_create.html.haml
  15. +1 −1  app/views/leads/_edit.html.haml
  16. +1 −1  app/views/opportunities/_create.html.haml
  17. +1 −1  app/views/opportunities/_edit.html.haml
  18. +1 −1  app/views/passwords/edit.html.haml
  19. +2 −2 app/views/passwords/new.html.haml
  20. +1 −1  app/views/tasks/_create.html.haml
  21. +1 −1  app/views/tasks/_edit.html.haml
  22. +2 −2 app/views/users/_avatar.html.haml
  23. +1 −1  app/views/users/_password.html.haml
  24. +1 −1  app/views/users/_profile.html.haml
  25. +1 −1  app/views/users/new.html.haml
  26. +0 −15 spec/views/admin/users/edit.haml_spec.rb
4 CHANGELOG
View
@@ -4,6 +4,10 @@ It does not matter how slowly you go as long as you do not stop.
First they ignore you, then they laugh at you, then they fight you,
then you win. –- Mahatma Gandhi
+Fri, Oct 9, 2009
+---------------------------------------------------------------------
+- Prevent multiple form submissions by pressing [Submit] button twice.
+
Wed, Oct 7, 2009
---------------------------------------------------------------------
- Moved [uses_user_permission] code from plugin to core library.
5 app/helpers/application_helper.rb
View
@@ -130,6 +130,11 @@ def invisible; { :style => "visibility:hidden;" }; end
def visible; { :style => "visibility:visible;" }; end
#----------------------------------------------------------------------------
+ def one_submit_only(form)
+ { :onsubmit => "$('#{form}_submit').disabled = true" }
+ end
+
+ #----------------------------------------------------------------------------
def hidden_if(you_ask)
you_ask ? hidden : exposed
end
4 app/views/accounts/_create.html.haml
View
@@ -1,4 +1,4 @@
-- remote_form_for(@account) do |f|
+- remote_form_for(@account, :html => one_submit_only(:account)) do |f|
= link_to_close new_account_path
= hidden_field_tag "account[user_id]", @current_user.id
= f.error_messages
@@ -6,7 +6,7 @@
= render :partial => "accounts/contact_info", :locals => { :f => f }
= render :partial => "accounts/permissions", :locals => { :f => f }
.buttonbar
- = f.submit "Create Account"
+ = f.submit "Create Account"
or
= link_to_cancel new_account_path
4 app/views/accounts/_edit.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for(@account) do |f|
+ - remote_form_for(@account, :html => one_submit_only(:account)) do |f|
= link_to_close edit_account_path(@account)
= f.hidden_field :user_id
= f.error_messages
@@ -7,6 +7,6 @@
= render :partial => "accounts/contact_info", :locals => { :f => f, :edit => true }
= render :partial => "accounts/permissions", :locals => { :f => f, :edit => true }
.buttonbar
- = f.submit "Save Account"
+ = f.submit "Save Account"
or
= link_to_cancel edit_account_path(@account)
2  app/views/admin/users/_create.html.haml
View
@@ -1,4 +1,4 @@
-- remote_form_for([:admin, @user]) do |f|
+- remote_form_for([:admin, @user], :html => one_submit_only(:user)) do |f|
= link_to_close new_admin_user_path
= f.error_messages
= render :partial => "admin/users/profile", :locals => { :f => f }
2  app/views/admin/users/_edit.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for([:admin, @user]) do |f|
+ - remote_form_for([:admin, @user], :html => one_submit_only(:user)) do |f|
= link_to_close edit_admin_user_path(@user)
= f.error_messages
= render :partial => "admin/users/profile", :locals => { :f => f, :edit => true }
13 app/views/admin/users/edit.html.haml
View
@@ -1,13 +0,0 @@
-.title Edit #{@user.full_name}
-%p
-:erb
- <% form_for([ :admin, @user ]) do |f| %>
- <%= f.error_messages %>
-
- <p>
- <%= f.submit 'Update' %>
- </p>
- <% end %>
-
- <%= link_to 'Show', admin_user_path(@user) %> |
- <%= link_to 'Back', admin_users_path %>
2  app/views/authentications/new.html.haml
View
@@ -13,7 +13,7 @@
.standalone#standalone
-# The following form gets submitted to #create when @authentication is nil,
-# or to #update when @authentication is not nil (ex. suspended).
- - form_for @authentication, :url => authentication_path do |f|
+ - form_for @authentication, :url => authentication_path, :html => one_submit_only(:authentication) do |f|
- if can_signup?
.title_tools== Don't have an account? #{link_to 'Sign Up Now!', signup_path}
.title Login
2  app/views/campaigns/_create.html.haml
View
@@ -1,4 +1,4 @@
-- remote_form_for(@campaign) do |f|
+- remote_form_for(@campaign, :html => one_submit_only(:campaign)) do |f|
= link_to_close new_campaign_path
= hidden_field_tag "campaign[user_id]", @current_user.id
= f.error_messages
2  app/views/campaigns/_edit.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for(@campaign) do |f|
+ - remote_form_for(@campaign, :html => one_submit_only(:campaign)) do |f|
= link_to_close edit_campaign_path(@campaign)
= f.hidden_field :user_id
= f.error_messages
2  app/views/contacts/_create.html.haml
View
@@ -1,4 +1,4 @@
-- remote_form_for(@contact) do |f|
+- remote_form_for(@contact, :html => one_submit_only(:contact)) do |f|
= link_to_close new_contact_path
= hidden_field_tag "opportunity", "#{@opportunity.id if @opportunity}"
= f.hidden_field :user_id
2  app/views/contacts/_edit.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for(@contact) do |f|
+ - remote_form_for(@contact, :html => one_submit_only(:contact)) do |f|
= link_to_close edit_contact_path(@contact)
= f.hidden_field :user_id
= f.error_messages
2  app/views/leads/_convert.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for(@lead, :url => promote_lead_path(@lead)) do |f|
+ - remote_form_for(@lead, :url => promote_lead_path(@lead), :html => one_submit_only(:lead)) do |f|
= link_to_close convert_lead_path(@lead)
- fields_for(@account) do |a|
= a.hidden_field :user_id
2  app/views/leads/_create.html.haml
View
@@ -1,4 +1,4 @@
-- remote_form_for(@lead) do |f|
+- remote_form_for(@lead, :html => one_submit_only(:lead)) do |f|
= link_to_close new_lead_path
= hidden_field_tag "campaign", "#{@campaign.id if @campaign}"
= hidden_field_tag "lead[user_id]", @current_user.id
2  app/views/leads/_edit.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for(@lead) do |f|
+ - remote_form_for(@lead, :html => one_submit_only(:lead)) do |f|
= link_to_close edit_lead_path(@lead)
= f.hidden_field :user_id
= f.error_messages
2  app/views/opportunities/_create.html.haml
View
@@ -1,4 +1,4 @@
-- remote_form_for(@opportunity) do |f|
+- remote_form_for(@opportunity, :html => one_submit_only(:opportunity)) do |f|
= link_to_close new_opportunity_path
= hidden_field_tag "contact", "#{@contact.id if @contact}"
= hidden_field_tag "campaign", "#{@campaign.id if @campaign}"
2  app/views/opportunities/_edit.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for(@opportunity) do |f|
+ - remote_form_for(@opportunity, :html => one_submit_only(:opportunity)) do |f|
= link_to_close edit_opportunity_path(@opportunity)
= f.hidden_field :user_id
= f.hidden_field :campaign_id
2  app/views/passwords/edit.html.haml
View
@@ -1,5 +1,5 @@
.standalone
- - form_for @user, :url => password_path, :method => :put do |f|
+ - form_for(@user, :url => passwords_path, :html => one_submit_only(:user), :method => :put) do |f|
.title Reset Password
= f.error_messages
.intro Please type your new password and then confirm it.
4 app/views/passwords/new.html.haml
View
@@ -1,5 +1,5 @@
.standalone
- - form_tag passwords_path do
+ - form_tag(passwords_path, one_submit_only(:passwords)) do
.title Forgot Password
.intro Please specify your email address and the instructions to reset your password will be sent to you.
.section
@@ -7,4 +7,4 @@
= text_field_tag :email
%br
.buttonbar
- = submit_tag "Reset Password"
+ = submit_tag "Reset Password", :id => "passwords_submit"
2  app/views/tasks/_create.html.haml
View
@@ -1,4 +1,4 @@
-- remote_form_for(@task) do |f|
+- remote_form_for(@task, :html => one_submit_only(:task)) do |f|
= link_to_close new_task_path + "?view=#{@view}"
= hidden_field_tag :view, @view
= hidden_field_tag "task[user_id]", @current_user.id
2  app/views/tasks/_edit.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for(@task) do |f|
+ - remote_form_for(@task, :html => one_submit_only(:task)) do |f|
= link_to_close edit_task_path(@task)
= hidden_field_tag :view, @view
= hidden_field_tag "task[asset_id]", "#{@asset.id if @asset}"
4 app/views/users/_avatar.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - form_for(@user, :url => upload_avatar_user_path(@user, :format => "js"), :html => { :multipart => true, :target => "uploading" }) do |f|
+ - form_for(@user, :url => upload_avatar_user_path(@user, :format => "js"), :html => { :multipart => true, :target => "uploading", :onsubmit => "$('user_submit).disabled = true" }) do |f|
= link_to_close avatar_user_path(@user)
= error_messages_for :avatar, :object => @user.avatar
@@ -12,7 +12,7 @@
.buttonbar
%small.cool{:style => "float:right"}== Not familiar with Gravatars? Learn about Gravatars #{link_to("here", "http://en.gravatar.com", :popup => true)}.
- = f.submit "Upload Picture"
+ = f.submit "Upload Picture", :onclick => "this.disabled = true"
or
= link_to_remote("Use Gravatar", :url => upload_avatar_user_path(@user), :method => :put, :with => "'gravatar=1'")
or
2  app/views/users/_password.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for(@user, :url => change_password_user_path(@user)) do |f|
+ - remote_form_for(@user, :url => change_password_user_path(@user), :html => one_submit_only(:user)) do |f|
= link_to_close password_user_path(@user)
= f.error_messages
.section
2  app/views/users/_profile.html.haml
View
@@ -1,5 +1,5 @@
.remote
- - remote_form_for(@user) do |f|
+ - remote_form_for(@user, :html => one_submit_only(:user)) do |f|
= link_to_close edit_user_path(@user)
= f.error_messages
.section
2  app/views/users/new.html.haml
View
@@ -1,5 +1,5 @@
.standalone
- - form_for @user do |f|
+ - form_for(@user, :html => one_submit_only(:user)) do |f|
.title_tools== Already signed up? #{link_to "Login Now!", login_path}
.title Sign Up
= f.error_messages
15 spec/views/admin/users/edit.haml_spec.rb
View
@@ -1,15 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
-
-describe "/admin/users/edit.html.haml" do
- include Admin::UsersHelper
-
- before(:each) do
- login_and_assign(:admin => true)
- assigns[:user] = @user = Factory(:user)
- end
-
- it "renders the edit user form" do
- render
- response.should have_tag("form[action=#{admin_user_path(@user)}][class=edit_user]")
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.