Hi All,
I know that eform has bundled validation, but let’s say I wanted to use jQuery’s validation plugin. It does validation clientside. I wanted to do this because it would be easy for me to create the simple math problem spam check. I thought I’d share how I did it and then ask for feedback.
I add these lines to the form
<p>Solve this simple math Problem and the continue button will appear</p>
<span id="rnuma"></span> + <span id="rnumb"></span> =
<input type="text" value="" id="testInput" style="width: 3em;" />
<span class="green Button" id="mathTest" />Test Me</span><br />
and then I include the jquery library, jquery validate plugin and use this small bit of code to validate.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script> <!--For newbies it is important to add jQuery before the jQuery plugin below. -->
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.js"></script>
<script>
jQuery(function ($) {
$("#joinForm").validate(); //replace #joinform with id of form you are using
var rnuma = Math.floor(Math.random() * 11);
var rnumb = Math.floor(Math.random() * 11);
var sum = rnuma + rnumb;
$("#rnuma").text(rnuma);
$("#rnumb").text(rnumb);
$("#mathTest").click(function(){
if (sum == $("#testInput").val())
{$("form").append("<p><input type='submit' value='continue to step 2' id='cfContact' /></p>");}
else {alert('sorry, please try again.');}
});
});
</script>
I thought it was easy to implement, but I’m looking to know if spambots can spoof it or if it is good solution. I know that the user has to have javascript turned on for the validation to work, but again I’m looking for insight.
To learn about the plugin and to download it, go to
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
-Noah