55 * @author Raspgot
66 */
77
8- const publicKey = "" ; // GOOGLE public key
8+ const publicKey = '' ; // GOOGLE public key
99
1010$ ( function ( ) {
1111 check_grecaptcha ( ) ;
1212
1313 // If you add field, add rule and error message in validate function
14- $ ( " #contactform" ) . validate ( {
14+ $ ( ' #contactform' ) . validate ( {
1515 // Form fields rules
1616 rules : {
1717 name : {
1818 required : true ,
19- minlength : 3
19+ minlength : 3 ,
2020 } ,
2121 email : {
2222 required : true ,
23- email : true
23+ email : true ,
2424 } ,
2525 message : {
2626 required : true ,
27- minlength : 5
28- }
27+ minlength : 5 ,
28+ } ,
2929 } ,
3030 // Error messages
3131 messages : {
3232 name : {
33- required : " Please enter your name." ,
34- minlength : " Must be at least 3 characters long."
33+ required : ' Please enter your name.' ,
34+ minlength : ' Must be at least 3 characters long.' ,
3535 } ,
36- email : " Please enter a valid email." ,
36+ email : ' Please enter a valid email.' ,
3737 message : {
38- required : " Please enter your message." ,
39- minlength : " Must be at least 5 characters long."
40- }
38+ required : ' Please enter your message.' ,
39+ minlength : ' Must be at least 5 characters long.' ,
40+ } ,
4141 } ,
42- errorClass : " invalid-feedback" ,
42+ errorClass : ' invalid-feedback' ,
4343 // Dynamic validation classes
4444 highlight : function ( element ) {
4545 // Invalid
46- $ ( element ) . addClass ( " is-invalid" ) . removeClass ( " is-valid" ) ;
46+ $ ( element ) . addClass ( ' is-invalid' ) . removeClass ( ' is-valid' ) ;
4747 } ,
4848 unhighlight : function ( element ) {
4949 // Valid
50- $ ( element ) . addClass ( " is-valid" ) . removeClass ( " is-invalid" ) ;
50+ $ ( element ) . addClass ( ' is-valid' ) . removeClass ( ' is-invalid' ) ;
5151 } ,
5252 // Action on submit
5353 submitHandler : function ( form , event ) {
5454 event . preventDefault ( ) ;
55- $ ( " #sendtext" ) . text ( " SENDING..." ) ;
55+ $ ( ' #sendtext' ) . text ( ' SENDING...' ) ;
5656 $ . post ( form . action , $ ( form ) . serialize ( ) )
5757 . done ( function ( response ) {
5858 alertShowing ( JSON . parse ( response ) ) ;
59- $ ( " #sendtext" ) . text ( " SEND" ) ;
60- $ ( " #submit-btn" ) . prop ( " disabled" , true ) ;
59+ $ ( ' #sendtext' ) . text ( ' SEND' ) ;
60+ $ ( ' #submit-btn' ) . prop ( ' disabled' , true ) ;
6161 check_grecaptcha ( ) ;
6262 } )
6363 . fail ( function ( response ) {
@@ -66,40 +66,44 @@ $(function () {
6666 . always ( function ( ) {
6767 // Timeout to reset form
6868 setTimeout ( function ( ) {
69- $ ( "#submit-btn" ) . prop ( "disabled" , false ) ;
70- $ ( "form" ) . trigger ( "reset" ) ;
71- $ ( "form" ) . each ( function ( ) {
72- $ ( this ) . find ( ".form-control" ) . removeClass ( "is-valid" )
73- } )
69+ $ ( '#submit-btn' ) . prop ( 'disabled' , false ) ;
70+ $ ( 'form' ) . trigger ( 'reset' ) ;
71+ $ ( 'form' ) . each ( function ( ) {
72+ $ ( this )
73+ . find ( '.form-control' )
74+ . removeClass ( 'is-valid' ) ;
75+ } ) ;
7476 } , 3000 ) ;
7577 } ) ;
76- }
78+ } ,
7779 } ) ;
7880} ) ;
7981
8082// Get token from API
8183function check_grecaptcha ( ) {
8284 grecaptcha . ready ( function ( ) {
83- grecaptcha . execute ( publicKey , {
84- action : "ajaxForm"
85- } ) . then ( function ( token ) {
86- $ ( "[name='recaptcha-token']" ) . val ( token ) ;
87- } ) ;
85+ grecaptcha
86+ . execute ( publicKey , {
87+ action : 'ajaxForm' ,
88+ } )
89+ . then ( function ( token ) {
90+ $ ( "[name='recaptcha-token']" ) . val ( token ) ;
91+ } ) ;
8892 } ) ;
8993}
9094
9195// Show response in .alert
9296function alertShowing ( response ) {
9397 // Apply class alert
9498 if ( response . error == true ) {
95- $ ( " #response-alert" ) . addClass ( " alert-danger" ) ;
96- $ ( " #response-alert" ) . removeClass ( " alert-success" ) ;
99+ $ ( ' #response-alert' ) . addClass ( ' alert-danger' ) ;
100+ $ ( ' #response-alert' ) . removeClass ( ' alert-success' ) ;
97101 } else {
98- $ ( " #response-alert" ) . addClass ( " alert-success" ) ;
99- $ ( " #response-alert" ) . removeClass ( " alert-danger" ) ;
102+ $ ( ' #response-alert' ) . addClass ( ' alert-success' ) ;
103+ $ ( ' #response-alert' ) . removeClass ( ' alert-danger' ) ;
100104 }
101105 // Display alert with message
102- $ ( " #response-alert" ) . html ( response . message ) ;
103- $ ( " #response-alert" ) . removeClass ( " d-none" ) ;
104- $ ( " #response-alert" ) . addClass ( " d-block" ) ;
106+ $ ( ' #response-alert' ) . html ( response . message ) ;
107+ $ ( ' #response-alert' ) . removeClass ( ' d-none' ) ;
108+ $ ( ' #response-alert' ) . addClass ( ' d-block' ) ;
105109}
0 commit comments