Skip to content

Commit 063205a

Browse files
authored
Merge pull request #24 from gonzomir/master
Simplify form data serialization when submitting form with AJAX. Props @gonzomir
2 parents 57d2e53 + 34d3cc6 commit 063205a

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

public/js/gdrf-public.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
( function( $ ) {
22
'use strict';
3-
3+
44
jQuery(document).ready(function() {
55

66
$( '#gdrf-form' ).on( 'submit', function( event ) {
7-
7+
88
event.preventDefault();
9-
10-
var data_type = '';
11-
if ( $( 'input[name=gdrf_data_type]' ).is( ':checkbox' ) ) {
12-
data_type = $( 'input[name=gdrf_data_type]:checked', '#gdrf-form').val();
13-
} else {
14-
data_type = $( 'input[name=gdrf_data_type]', '#gdrf-form').val();
15-
}
16-
17-
var button = $( '#gdrf-submit-button' ),
18-
data = {
19-
'action': 'gdrf_data_request',
20-
'gdrf_data_type' : data_type,
21-
'gdrf_data_human_key': $( '#gdrf_data_human_key' ).val(),
22-
'gdrf_data_email': $( '#gdrf_data_email' ).val(),
23-
'gdrf_data_human': $( '#gdrf_data_human' ).val(),
24-
'gdrf_data_nonce': $( '#gdrf_data_nonce' ).val(),
25-
};
9+
10+
var data = $( this ).serialize();
2611

2712
$( '.gdrf-errors' ).remove();
2813
$( '.gdrf-success' ).remove();

0 commit comments

Comments
 (0)