/*
function setFormSubmissionHandler(selector, options) {
var formElement = document.querySelector(selector);
var errorElement = document.querySelector(options.errorSelector);
var successElement = document.querySelector(options.successSelector);
var errorMsgElement = document.querySelector(options.errorMsgSelector);
// Submit event is only fired after form validation
formElement.addEventListener('submit', function(event) {
// Prevent default behavior, for example, send info to page.
event.preventDefault();
// Create payload as new FormData object:
const payload = new FormData(formElement);
// Post the payload using Fetch:
fetch(options.url, {
method: options.method || 'POST',
body: payload,
})
.then(function(response) {
if (!response.ok) {
return Promise.reject('Error from server');
} else {
successElement.style.display = 'block';
formElement.style.display = 'none';
}
})
.then()
.catch(function(err) {
errorMsgElement.textContent = options.errorMessage;
errorElement.style.display = 'block';
formElement.style.display = 'none';
console.log(err);
})
})
}
setFormSubmissionHandler('#form', {
successSelector: '#form-success',
errorSelector: '#form-error',
errorMsgSelector: '#form-error-message',
url: 'https://hook.integromat.com/rd5b3e79fve8vqrjk5ugbteemvbnrh7j',
method: 'POST',
errorMessage: 'Ha ocurrido un error al enviar el formulario. Por favor inténtalo de nuevo. Si el problema persiste, puedes escribir a info(at)romerodfran.com'
});
//
*/