I am trying to send contact us form details to Insightly CRM with Web to Lead html code. I changed action url of the form with the following code in my functions.php:
add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url($url) {
global $post;
$id_to_change = 1315;
if($post->ID === $id_to_change)
return 'https://xxxx.insight.ly/WebToLead/Create';
else
return $url;
}
Everything looks fine on inspector but i get the following error on submit:
XMLHttpRequest cannot load https://xxxx.insight.ly/WebToLead/Create. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xxxx.com' is therefore not allowed access.
I tried adding this to my functions.php:
add_action( 'init', 'allow_origin' );
function allow_origin() {
header("Access-Control-Allow-Origin: *");
}
I tried adding this in theme.php:
header("Access-Control-Allow-Origin: *");
I tried adding this to scripts.js of contact form 7 plugin:
$.ajax({
url: url,
++headers: { 'Access-Control-Allow-Origin': '*' },
++crossDomain: true,
I tried adding this to .htaccess:
Header always set Access-Control-Allow-Origin "*"
Nothing works :( My server has Varnish 4 and ConfigServer Security & Firewall but i disabled both and still get the same error. Please help me :(