Hi, for everyone struggling with this here is an alternate solution I used in "contact form" but should also apply to "send friend":
1. Modify form header to this:
<form id="contact_form" name="contact_form">
2. Change the submit button to this:
<button id="send_btn" type="button" onclick="submitform();"><?php _e('Send', '[yourtheme]') ; ?></button>
3. Add this script
function submitform(){
if(document.contact_form.onsubmit()){ //the condition is needed to perform my custom validations, can be ignored.
noredirect();
}
}
function noredirect(){
$.ajax({
url: "<?php echo osc_base_url(true);?>",
data: $("#contact_form").serialize(),
context: document.body,
success: function(res){
alert ( $(res).filter("#FlashMessage").html() ); // here we capture the response (FlashMessage div) and display it.
// your custom code to handle success/error messages
},
error: function(){
//TODO
}
});
}
This way you can take advantage of the many available response messages for the "contact_form", for example when recaptcha is wrong.
Regards.