Skip to content

Commit

Permalink
Merge pull request #24 from gonzomir/master
Browse files Browse the repository at this point in the history
Simplify form data serialization when submitting form with AJAX.
Props @gonzomir
  • Loading branch information
audrasjb authored Aug 28, 2019
2 parents 57d2e53 + 34d3cc6 commit 063205a
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions public/js/gdrf-public.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
( function( $ ) {
'use strict';

jQuery(document).ready(function() {

$( '#gdrf-form' ).on( 'submit', function( event ) {

event.preventDefault();

var data_type = '';
if ( $( 'input[name=gdrf_data_type]' ).is( ':checkbox' ) ) {
data_type = $( 'input[name=gdrf_data_type]:checked', '#gdrf-form').val();
} else {
data_type = $( 'input[name=gdrf_data_type]', '#gdrf-form').val();
}

var button = $( '#gdrf-submit-button' ),
data = {
'action': 'gdrf_data_request',
'gdrf_data_type' : data_type,
'gdrf_data_human_key': $( '#gdrf_data_human_key' ).val(),
'gdrf_data_email': $( '#gdrf_data_email' ).val(),
'gdrf_data_human': $( '#gdrf_data_human' ).val(),
'gdrf_data_nonce': $( '#gdrf_data_nonce' ).val(),
};

var data = $( this ).serialize();

$( '.gdrf-errors' ).remove();
$( '.gdrf-success' ).remove();
Expand Down

0 comments on commit 063205a

Please sign in to comment.