Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Firas Khalifeh 11 posts 42 karma points
    Apr 29, 2012 @ 11:48
    Firas Khalifeh

    Captcha or other way to protect My Contact Form :)

    Hey Umbracian,

    do you know a way to protect a Contact form, I am using RVContactForm, which is using Ajax to post the form.
    I want to protect the form through Captcha ( as far as i know ) or if you prefer other solution.

    is there a solution to make it work out with AJAX and without a lot of code !!?

    Thanks in advance :)




  • Eran 292 posts 436 karma points
    Apr 29, 2012 @ 12:36


    there is a lot of possibilities to do that:

    you have technics that unrelated to umbraco but can be used, like aksimet or stuff like this.

    and of course you can examine one of the umbraco packages that using spam filters and take to right code from it.

    please update me if you will develop something nice. maybe i will consider to insert it to future update of the RVContactForm package.




  • Firas Khalifeh 11 posts 42 karma points
    Apr 30, 2012 @ 11:57
    Firas Khalifeh

    Hi Eran,

    here is the solution for this:

    I used google Recaptcha

    I will put the steps below, just to help other to integrate it, but it would be better to integrate it with your solution :).

    in the dll source code (the webservice) i have added a method:

            [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
            public bool ValidateCaptcha(string challengeValue, string responseValue)
                Recaptcha.RecaptchaValidator captchaValidtor = new Recaptcha.RecaptchaValidator
                    PrivateKey = Convert.ToString(ConfigurationManager.AppSettings["ReCaptchaPrivateKey"]), // Get Private key of the CAPTCHA from Web.config file.
                    RemoteIP = HttpContext.Current.Request.UserHostAddress,
                    Challenge = challengeValue,
                    Response = responseValue
                Recaptcha.RecaptchaResponse recaptchaResponse = captchaValidtor.Validate(); // Send data about captcha validation to reCAPTCHA site.
                return recaptchaResponse.IsValid; // Get boolean value about Captcha success / failure.


    on the Page template 

      <script type="text/javascript" src="">script>    <script type="text/javascript">   $(document).ready(function(){    
     Recaptcha.create("Public Key!!",
              theme: "red",
              callback: Recaptcha.focus_response_field

    in the body a Div for My Captcha
     <div id="DivID">
    now edit the RVContactForm.js

    replace the code for sending with this one (ajaxSubmit) with this below:

    var captchaInfo =
                 challengeValue: Recaptcha.get_challenge(),
                 responseValue: Recaptcha.get_response()

             type: 'POST',
             url: '/umbraco/webservices/RVContactFormMailer.asmx/ValidateCaptcha',
             data: JSON.stringify(captchaInfo),
             contentType: 'application/json; charset=utf-8',
             dataType: 'json',
             success: CAPTCHASuccess,
             error: CAPTCHAFail

    add 2 new functions:

    function CAPTCHAFail(msg) {
         var str = 'say something';
     function CAPTCHASuccess(msg) {
     { var myMailerRequest= 'prepare some thing inside the message !!' // JSONify the js object - desirialize js object to MailerRequest object. the first param must be equal to the name of the input parameter in the web service method "SendContactForm"
                    var data = JSON.stringify({ req: myMailerRequest });
                        type: "POST",
                        url: "/umbraco/webservices/RVContactFormMailer.asmx/SendContactForm",
                        data: data,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: AjaxSucceeded,
                        error: AjaxFailed
         else {
             alert('Please enter a Correct Captcha');
    function AjaxSucceeded(result) {
         //some jquery transformation and animation for appending result !!
     function AjaxFailed(result) {
        // tell the user about the failure !!

    hope it help some Umbracian around :)




Please Sign in or register to post replies

Write your reply to: