The script from the post above works fine with Basin and shows the build-in Webflow success/fail-messages.
<script type="text/javascript">
//apply only to forms with the action pointing to Basin
$('form[action^="https://mydomain.com"]').each(function(i,el){
form = $(el);
form.submit(function(e){
//stop the form from submitting
e.preventDefault();
form = $(e.target);
//submit the form via ajax
$.ajax({
method: "POST",
url: form.attr('action'),
data: form.serialize(),
success: function(data){
if(data.success){
//successful submission - hide the form and show the success message
parent = $(form.parent());
parent.children('form').css('display','none');
parent.children('.w-form-done').css('display','block');
} else {
//failed submission - log the output to the console and show the failure message
parent.find('.w-form-fail').css('display','block');
}
},
error: function(){
//failed submission - show the failure message
parent.find('.w-form-fail').css('display','block');
}
});
});
});
</script>
I donât know why, but for any reason my script wonât show the success or failed message. Any idea what I did wrong? The PHP script seems to work, because Iâll get an email with the form-data.
You might need to customize the javascript a little bit more, depending on the output of your pho script. The JS is expecting an AJAX response, and it expects a parameter called âsuccessâ with its value set to true. You might need to modify the âif(data.success){â line to match what your php script is returning.
For troubleshooting, you might want to look in the JS console to see what your PHP script is returning. If you add a console.log(data) line to the JS code right before that âif(data.success)â line, the script output will be sent to the console.
You could also simplify things a bit. Have your PHP script just return the word âsuccessâ instead of a JSON responseâŚ
This is what I have and it works well. After reviewing this post and others I found nothing very helpful. You solution would work in theory but do you have no knowledge of what is going on on your PHP server?