Skip to content

Instantly share code, notes, and snippets.

@thanhcs94
Created June 5, 2018 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thanhcs94/b25bd10d7fc6b49976aaf5c5be898be3 to your computer and use it in GitHub Desktop.
Save thanhcs94/b25bd10d7fc6b49976aaf5c5be898be3 to your computer and use it in GitHub Desktop.
abc
<input type="text" name="firstName" id="firstName" data-email="required" placeholder="Họ và tên" class="medium-input border-radius-4" style="color: rgb(112, 112, 112); background-color: rgb(255, 255, 255); border-color: rgb(153, 153, 153); font-size: 14px; font-weight: 400; font-family: 'Open Sans', sans-serif; text-transform: none; border-radius: 4px;" required >
<input type="number" name="phone" id="phone" placeholder="Số điện thoại" class="medium-input border-radius-4" required>
<input type="email" name="email" id="email" data-email="required" placeholder="Địa chỉ Email" class="medium-input border-radius-4">
<script>
// Parse the URL
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// Give the URL parameters variable names
var source = getParameterByName('utm_source');
var medium = getParameterByName('utm_medium');
var campaign = getParameterByName('utm_campaign');
// Put the variable names into the hidden fields in the form.
document.getElementsByName("utm_source").value = source;
document.getElementsByName("utm_medium").value = medium;
document.getElementsByName("utm_campaign").value = campaign;
const scriptURL = 'https://script.google.com/macros/s/AKfycbzxZx9B4dSQP28sOENOmRycB9wQvsGsTimkWnHEff1R7Y2GpMsc/exec'
const form = document.forms['submit-to-google-sheet']
const loading = document.querySelector('.js-loading')
const successMessage = document.querySelector('.js-success-message')
const errorMessage = document.querySelector('.js-error-message')
form.addEventListener('submit', e => {
e.preventDefault()
showLoadingIndicator()
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => showSuccessMessage(response))
.catch(error => showErrorMessage(error))
})
function showLoadingIndicator () {
// form.classList.add('is-hidden')
// loading.classList.remove('is-hidden')
}
function showSuccessMessage (response) {
window.location.assign("/guihang24h/gui_thanh_cong.html");
setTimeout(() => {
// successMessage.classList.remove('is-hidden')
// loading.classList.add('is-hidden')
}, 500)
}
function showErrorMessage (error) {
window.location.assign("/guihang24h/gui_thanh_cong.html");
console.log(""+error);
setTimeout(() => {
// errorMessage.classList.remove('is-hidden')
// loading.classList.add('is-hidden')
}, 500)
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment