We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34072
    • 31 Posts
    Hi everyone,

    I’m using eform in ModX Evo 1.0.4 to create a voting form. I’d like to somehow prevent people from submitting more than one vote, either by filtering their email address (a required field in the form), IP address, or by any other means. I’ve never done this before and want to know, is it possible?

    Is there an easy way to do this in eform?

    Thanks, Kahli
      • 14352
      • 9 Posts
      You could do this with JavaScript.

      Here is an jQuery example wich disables the button after clicking on it:
      //Prevent form double-submission
      $('form').submit(function(){
      	$('input[type=submit]', this).attr('disabled', 'disabled');
      });
      


      Then you could use cookies to prevent people from reloading the page and submitting the form more than once.
      Check out these pages for some examples:
      http://www.electrictoolbox.com/jquery-cookies/
      http://jquery-howto.blogspot.com/2010/09/jquery-cookies-getsetdelete-plugin.html

      Example:
      var cookie_name = 'submitCheck';
      
      $('form').submit(function(){
      	//Disable button
      	$('input[type=submit]', this).attr('disabled', 'disabled');
      	//Set cookie
      	$.cookie(cookie_name, "submitted");		
      });
      
      // if form is submitted, add class to form
      if ($.cookie(cookie_name) == "submitted") {  
      	$("form").addClass("submitted");
      } 
      


      Then you could use css to hide the submit button.

      form.submitted input[type=submit {
      	display:none;
      }
      


      Just a quick n dirty example, not tested and does not guarantee multiple submits (people can remove the cookie)
      It should give an idea though.
      A solution wich checks IP’s should be better.