2020-03-14 20:02:57 +00:00
function serializeForm ( form ) {
var result = { } ;
$ . map ( form . serializeArray ( ) , function ( n , i ) {
result [ n [ 'name' ] ] = n [ 'value' ] ;
} ) ;
return result ;
} ;
$ ( document ) . ready ( function ( ) {
var meetup _form = $ ( '#meetup-form' ) ;
$ ( "#meetup-form-send" ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
var valid = true ;
var required _fields = $ ( '#meetup-form input[required="true"]' ) ;
$ . each ( required _fields , function ( idx ) {
var input = $ ( required _fields [ idx ] ) ;
if ( ! input . val ( ) ) {
valid = false ;
input . addClass ( 'border-danger' ) ;
} else {
input . removeClass ( 'border-danger' ) ;
}
} ) ;
if ( valid ) {
var data = JSON . stringify ( serializeForm ( meetup _form ) ) ;
$ . ajax ( {
url : '/meet-form/' ,
type : 'POST' ,
dataType : 'json' ,
data : data ,
success : function ( ) {
2020-05-19 10:45:02 +00:00
meetup _form . html ( '<div class="alert alert-success"><h2>Thanks!</h2><p class="lead">We\'ll be in touch soon.</p></div>' ) ;
2020-03-14 20:02:57 +00:00
$ ( '#meetup-form-error' ) . html ( '' ) ;
} ,
error : function ( ) {
2020-05-19 10:45:02 +00:00
$ ( '#meetup-form-error' ) . html ( '<div class="alert alert-danger mt-3"><strong>Error!</strong> Unfortunately it didn\'t work for some reason, please try again or use the email address below.</div>' ) ;
2020-03-14 20:02:57 +00:00
}
} ) ;
}
return false ;
} ) ;
} ) ;