script.js
54 lines
| 1 | (function( $ ) { |
| 2 | var gglcptch_match = true; |
| 3 | $( document ).ready(function() { |
| 4 | $( '#recaptcha_widget_div' ).parent().children( 'input:submit' ).click(function() { |
| 5 | click_trigger(); |
| 6 | return gglcptch_match; |
| 7 | }); |
| 8 | $( '#cntctfrm_contact_form' ).find( 'input:submit' ).click(function() { |
| 9 | click_trigger(); |
| 10 | return gglcptch_match; |
| 11 | }); |
| 12 | }); |
| 13 | |
| 14 | function click_trigger() { |
| 15 | var req = getXmpHttp(); |
| 16 | /* fields for checking Google Captcha */ |
| 17 | var recaptcha_challenge_field = $( '#recaptcha_challenge_field' ).val(); |
| 18 | var recaptcha_response_field = $( '#recaptcha_response_field' ).val(); |
| 19 | /* opening asynchronous connection */ |
| 20 | req.open( 'POST', gglcptch_path, false ); |
| 21 | req.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); |
| 22 | /* sending POST parameters */ |
| 23 | req.send( 'recaptcha_challenge_field=' + recaptcha_challenge_field + '&recaptcha_response_field=' + recaptcha_response_field + '&gglcptch_private_key=' + gglcptch_private_key ); |
| 24 | |
| 25 | if ( req.responseText == 'error' ) { |
| 26 | /* wrong captcha */ |
| 27 | if ( ! $( '#gglcptch_error' ).text() ) { |
| 28 | $( '#recaptcha_widget_div' ).after( '<label id="gglcptch_error" style="color:#f00;">' + gglcptch_error_msg + '</label>' ); |
| 29 | gglcptch_match = false; |
| 30 | } |
| 31 | } else { |
| 32 | /* correct catcha */ |
| 33 | gglcptch_match = true; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /* Creating xmlhttp object */ |
| 38 | function getXmpHttp() { |
| 39 | var xmlhttp; |
| 40 | try { |
| 41 | xmlhttp = new ActiveXObject( 'Msxml2.XMLHTTP' ); |
| 42 | } catch ( e ) { |
| 43 | try { |
| 44 | xmlhttp = new ActiveXObject( 'Microsoft.XMLHTTP' ); |
| 45 | } catch ( E ) { |
| 46 | xmlhttp = false; |
| 47 | } |
| 48 | } |
| 49 | if ( ! xmlhttp && typeof XMLHttpRequest != 'undefined' ) { |
| 50 | xmlhttp = new XMLHttpRequest(); |
| 51 | } |
| 52 | return xmlhttp; |
| 53 | } |
| 54 | })(jQuery); |