-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
51 lines (43 loc) · 1.3 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Created by Javier Misat
* Company: Innovamos
* Description:
* Date: 25/03/2019
* Time: 1:30 AM
*/
// Prevenir multiples envíos de WPCF7 forms
add_action('wp_footer', 'validar_envio_cf7');
function validar_envio_cf7()
{
?>
<script type="text/javascript">
let disableSubmit = false;
let objInput = null;
let enviarValue = null;
try {
objInput = document.querySelector('.wpcf7-submit');
enviarValue = objInput.value;
} catch (e) {
objInput = document.querySelector('.wpcf7 button[type="submit"]');
enviarValue = objInput.textContent;
}
objInput.addEventListener('click', function (e) {
objInput.setAttribute('value', 'Enviando...');
objInput.textContent = 'Enviando...';
if (disableSubmit == true) {
e.preventDefault();
return false;
}
disableSubmit = true;
return true;
});
let wpcf7Elm = document.querySelector('.wpcf7');
wpcf7Elm.addEventListener('wpcf7submit', function (event) {
objInput.setAttribute('value', enviarValue);
objInput.textContent = enviarValue;
disableSubmit = false;
}, false);
</script>
<?php
}