How to get what the user entered in Contact Form 7 and change it before sending? I have an input field, when the user submits the data I have to validate it and if there is anything to change, I tried many options but couldn’t find what I need.
For example, user write something, I need to compare it with JS variable, and change it in sending.
For minimal instance: You need WordPress, plugin ContactForm7, and for JS I used WoodySnippets. Create Contact Form with two fields and button.
Before sending:
<label>Doesn't need[text* text-564 placeholder ""]</label>
<label>Need[text* text-276 id:myform "5"]<label>
<button onclick="coinsCheck()">
<label>[submit "Submit"]</label>
</button>
and:
<script>
myfor = document.getElementById("myform").value;
function coinsCheck(){
alert(myfor);
if(myfor !== '6'){
alert(myfor);
}
}
function redCoin(decr){
a = 5;
decr = parseInt(decr)
a -= decr;
alert(a);
}
</script>
Here I output the variable, the first time just to know the value, the second time if it is not equal to 6.
But alert shows “null” twice(if snippet above form) or four times “[object HTMLInputElement]” if snippet below the form. And in console I have this error: Failed to load resource: too many HTTP redirects: http://1.gravatar.com/avatar/459d16a800ceb49fe2871a22c7041252?s=52&d=mm&r=g
After sending:
When I added updated script(because send_ok is deprecated) in additional settings of Contact Form 7 for checking variables, that I have, it didn’t work
wpcf7Elm.addEventListener( 'wpcf7mailsent', function( event ) {
alert( "Fire!" );
redCoin(myfor);
}, false );
What I am trying to do: check if input equals ‘6’, after mail is sent successfully, substact decr(decrease) from a(5)