1+ < p >
2+ < h2 > Join our newsletter</ h2 >
3+ Stay informed! One mail per month about DbGate, SQL and databases. We will not share your info with anyone.
4+ </ p>
5+
6+ < form >
7+ <!-- Newsletter Email -->
8+ < div class ="form-group mb-3 ">
9+ < input type ="email " class ="input " id ="newsletterEmail " placeholder ="Email addres " />
10+ < p class ="help is-danger " id ="email-error " style ="display: none "> Please enter valid e-mail</ p >
11+ </ div >
12+
13+ < p >
14+ < a onclick ="subscribeNewsletter() " class ="button is-info is-medium "> Subscribe </ a >
15+ </ p >
16+ </ form >
17+
18+ < script >
19+ async function subscribeNewsletter ( ) {
20+ const emailInput = document . getElementById ( 'newsletterEmail' ) ;
21+ const emailError = document . getElementById ( 'email-error' ) ;
22+ const email = emailInput . value ;
23+
24+ // Simple e-mail pattern
25+ const emailPattern = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
26+ if ( ! emailPattern . test ( email ) ) {
27+ emailInput . classList . add ( 'is-danger' ) ; // You could also handle is-invalid via .form-control
28+ emailError . style . display = 'block' ;
29+ return ;
30+ } else {
31+ emailInput . classList . remove ( 'is-danger' ) ;
32+ emailError . style . display = 'none' ;
33+ }
34+
35+ const data = {
36+ email : email ,
37+ } ;
38+
39+ try {
40+ const response = await fetch (
41+ 'https://api.dbgate.io/newsletter/dbgate.org' ,
42+ {
43+ method : 'POST' ,
44+ headers : {
45+ 'Content-Type' : 'application/json' ,
46+ } ,
47+ body : JSON . stringify ( data ) ,
48+ }
49+ ) ;
50+ alert ( 'Thank you for joining our newslette.' ) ;
51+ } catch ( error ) {
52+ console . error ( 'Error:' , error ) ;
53+ alert ( 'An error occurred while sending data.' ) ;
54+ }
55+ }
56+ </ script >
0 commit comments