Skip to content

Commit 98b278e

Browse files
author
Akanksha Raghav
authored
Merge pull request #138 from sureshmangs/master
Fixing issue: collecting email id's - From newsletter #95
2 parents 7946516 + a30dbfc commit 98b278e

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

assets/js/main.js

+47-3
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,57 @@ jQuery(document).ready(function() {
203203
// Ensures valid email is supplied
204204
$(".subscribe").click(function () {
205205
if (/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(document.getElementById('email').value)) {
206-
document.getElementById('email').value = ""
207206
document.getElementById('email').placeholder = "Thank you for subscribing to our newsletters."
208207
} else {
209208
document.getElementById('email').value = ""
210209
document.getElementById('email').placeholder = "Please enter a valid email address."
211210
}
212211
});
213212
})(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+
}

index.html

+16-6
Original file line numberDiff line numberDiff line change
@@ -825,12 +825,14 @@ <h3>Frequently Asked Questions</h3>
825825
<div class="col-sm-12">
826826
<div class="content">
827827
<h2>SUBSCRIBE TO OUR NEWSLETTER</h2>
828-
<div class="input-group">
829-
<input type="email" class="form-control" id="email" placeholder="Enter your email">
830-
<span class="input-group-btn">
831-
<button class="btn subscribe" type="submit" >Subscribe Now</button>
832-
</span>
833-
</div>
828+
<form id="newsletterForm">
829+
<div class="input-group">
830+
<input type="email" class="form-control" id="email" placeholder="Enter your email">
831+
<span class="input-group-btn">
832+
<button class="btn subscribe" type="submit" >Subscribe Now</button>
833+
</span>
834+
</div>
835+
</form>
834836
</div>
835837
</div>
836838
</div>
@@ -887,6 +889,14 @@ <h4>Contact Us</h4>
887889
<script src="assets/vendor/owl.carousel/owl.carousel.min.js"></script>
888890
<script src="assets/vendor/waypoints/jquery.waypoints.min.js"></script>
889891

892+
<!-- The core Firebase JS SDK is always required and must be listed first -->
893+
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-app.js"></script>
894+
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-database.js"></script>
895+
896+
<!-- TODO: Add SDKs for Firebase products that you want to use
897+
https://firebase.google.com/docs/web/setup#available-libraries -->
898+
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-analytics.js"></script>
899+
890900
<!-- Template Main JS File -->
891901
<script src="assets/js/main.js"></script>
892902

0 commit comments

Comments
 (0)