Skip to content

Commit

Permalink
Merge pull request #5 from gravityview/develop
Browse files Browse the repository at this point in the history
Arg…get back to jQuery because of annoying AJAX stuff.
  • Loading branch information
zackkatz committed Mar 18, 2021
2 parents 49bb305 + 96b2e2c commit 77a8866
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
32 changes: 13 additions & 19 deletions gravityforms-zero-spam.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Gravity Forms Zero Spam
* Plugin URI: https://gravityview.co?utm_source=plugin&utm_campaign=zero-spam&utm_content=pluginuri
* Description: Enhance Gravity Forms to include effective anti-spam measures—without using a CAPTCHA.
* Version: 1.0.6.1
* Version: 1.0.7
* Author: GravityView
* Author URI: https://gravityview.co?utm_source=plugin&utm_campaign=zero-spam&utm_content=authoruri
* License: GPL-2.0+
Expand Down Expand Up @@ -69,24 +69,18 @@ public function get_key() {
public function add_key_field() {
?>
<script type='text/javascript'>
document.addEventListener("DOMContentLoaded", function() {
var gforms = '.gform_wrapper form';

var el = document.querySelector( gforms );

if ( ! el ) {
return;
}

el.addEventListener( "submit", function ( e ) {
var input = document.createElement( "input" );
input.type = 'hidden';
input.name = 'gf_zero_spam_key';
input.value = '<?php echo esc_js( $this->get_key() ); ?>';

e.target.appendChild( input );
} );
});
if ( window.jQuery ) {
jQuery( document ).ready( function ( $ ) {
var gforms = '.gform_wrapper form';
$( document ).on( 'submit', gforms, function () {
$( '<input>' ).attr( 'type', 'hidden' )
.attr( 'name', 'gf_zero_spam_key' )
.attr( 'value', '<?php echo esc_js( $this->get_key() ); ?>' )
.appendTo( gforms );
return true;
} );
} );
}
</script>
<?php
}
Expand Down
5 changes: 5 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ No. For that, we recommend Ben Marshall‘s [WordPress Zero Spam plugin](https:/

== Changelog ==

= 1.0.7 on March 18, 2021 =

* Fixed: All entries marked as spam for AJAX-enabled forms. Sorry, folks! Won't happen again.
* Went back to using jQuery to listen to form submissions.

= 1.0.6.1 on March 15, 2021 =

* Fixed: JavaScript "null is not an object (evaluating 'el.addEventListener')" error on pages without a form
Expand Down

0 comments on commit 77a8866

Please sign in to comment.