@@ -203,13 +203,57 @@ jQuery(document).ready(function() {
203
203
// Ensures valid email is supplied
204
204
$ ( ".subscribe" ) . click ( function ( ) {
205
205
if ( / ^ [ a - z A - Z 0 - 9 . ! # $ % & ' * + / = ? ^ _ ` { | } ~ - ] + @ [ a - z A - Z 0 - 9 - ] + (?: \. [ a - z A - Z 0 - 9 - ] + ) * $ / . test ( document . getElementById ( 'email' ) . value ) ) {
206
- document . getElementById ( 'email' ) . value = ""
207
206
document . getElementById ( 'email' ) . placeholder = "Thank you for subscribing to our newsletters."
208
207
} else {
209
208
document . getElementById ( 'email' ) . value = ""
210
209
document . getElementById ( 'email' ) . placeholder = "Please enter a valid email address."
211
210
}
212
211
} ) ;
213
212
} ) ( jQuery ) ;
214
- // News letter Form
215
- // use email
213
+
214
+
215
+
216
+ // Storing Newsletter emails in Firebase DB
217
+
218
+ // Your web app's Firebase configuration
219
+ var firebaseConfig = {
220
+ apiKey : "XXXXXXXXXXX" ,
221
+ authDomain : "XXXXXXXXXXX" ,
222
+ databaseURL : "XXXXXXXXXXX" ,
223
+ projectId : "XXXXXXXXXXX" ,
224
+ storageBucket : "XXXXXXXXXXX" ,
225
+ messagingSenderId : "XXXXXXXXXXX" ,
226
+ appId : "XXXXXXXXXXX" ,
227
+ measurementId : "XXXXXXXXXXX"
228
+ } ;
229
+
230
+ // Initialize Firebase
231
+ firebase . initializeApp ( firebaseConfig ) ;
232
+ firebase . analytics ( ) ;
233
+
234
+ // Reference messages collection
235
+ var messagesRef = firebase . database ( ) . ref ( 'Emails' ) ;
236
+
237
+ document . getElementById ( 'newsletterForm' ) . addEventListener ( 'submit' , submitForm ) ;
238
+
239
+ //submit form
240
+ function submitForm ( e ) {
241
+ e . preventDefault ( ) ;
242
+
243
+ // Get values
244
+ var email = document . getElementById ( "email" ) . value ;
245
+
246
+ // Save message
247
+ saveMessage ( email ) ;
248
+
249
+ // Clear form
250
+ document . getElementById ( 'newsletterForm' ) . reset ( ) ;
251
+ }
252
+
253
+ // Save message to firebase
254
+ function saveMessage ( email ) {
255
+ var newMessageRef = messagesRef . push ( ) ;
256
+ newMessageRef . set ( {
257
+ email :email
258
+ } ) ;
259
+ }
0 commit comments