// JavaScript Document (handling Click on Clayton form functionality) jQuery(document).ready(function($) { let coclayton_form_elem = $( 'form#isave-at-belvedere-register' ); let coclayton_modal_wrapper = $( '#coclayton_modal_wrap' ); /* close modal window when button is clicked */ $( '.coclayton_modal_close' ).on( 'click', function (e) { e.preventDefault(); $(this).closest( '.coclayton_repsonse' ).fadeOut( 'medium' ); coclayton_modal_wrapper.fadeOut( 'medium' ); }); /* attach a submit handler to the form */ coclayton_form_elem.submit( function( e ) { /* stop form from submitting normally */ e.preventDefault(); /* get the action attribute from the
element */ let url = coclayton_form_elem.attr( 'action' ); let coclayton_firstname = $( '#firstname' ).val(); let coclayton_surname = $( '#surname' ).val(); let coclayton_email = $( '#email' ).val(); let coclayton_password = $( '#password' ).val(); coclayton_firstname = coclayton_firstname.trim(); coclayton_surname = coclayton_surname.trim(); coclayton_email = coclayton_email.trim(); coclayton_password = coclayton_password.trim(); if( coclayton_firstname.length && coclayton_surname.length && coclayton_email.length && coclayton_password.length ) { $.ajax({ url : url, type: "post", dataType: 'json', headers: { 'X-Requested-With': 'XMLHttpRequest' }, data: $( 'form#isave-at-belvedere-register' ).serialize(), success : function( response ) { if(response.errors) { if( typeof response.errors === "string" ) { var errorMessage = response.errors; } else if( response.errors.generic.length > 0 ) { var errorMessage = response.errors.generic[0]; } coclayton_modal_wrapper.fadeIn( 'medium' ); if( errorMessage.length ) { if( errorMessage == 'An account already exists with the provided email address.') { errorMessage = errorMessage + '

Forgot your password?'; } $( '#message_error_main p' ).html( errorMessage ); } coclayton_modal_wrapper.find( '#message_error' ).fadeIn( 'medium' ); } else { coclayton_modal_wrapper.fadeIn( 'medium' ); coclayton_modal_wrapper.find( '#message_success' ).fadeIn( 'medium' ); } }, error: function( error ) { coclayton_modal_wrapper.fadeIn( 'medium' ); coclayton_modal_wrapper.find( '#message_error' ).fadeIn( 'medium' ); } }); } else { if( !coclayton_firstname.length ) { $( 'fieldset#firstname_fieldset' ).addClass( 'error' ); } if( !coclayton_surname.length ) { $( 'fieldset#surname_fieldset' ).addClass( 'error' ); } if( !coclayton_email.length ) { $( 'fieldset#email_fieldset' ).addClass( 'error' ); } if( !coclayton_password.length ) { $( 'fieldset#password_fieldset' ).addClass( 'error' ); } } }); });