Redirect Contact Form 7 to third party site
- سُلَيْمَان بْن دَاوُوْد

- Feb 26, 2021
- 1 min read
The following code is used for redirecting to a third party site
add_action( 'wp_footer', 'ca_redirect_form',9999);
function ca_redirect_form() {
$thankyoulink = get_field('redirect_url', 'option');
$wpcf7 = WPCF7_ContactForm::get_current();
$form_id = $wpcf7->id;
?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
setCookie('user_cookied','yes',3650);
console.log('user cookied');
var inputs = event.detail.inputs;
if(event.detail.contactFormId == '21653'){
jQuery('#whitepapercookie').hide();
var sharpurl = jQuery('#sharpwhitepaperurl').val();
window.location.href = sharpurl;
}else{
var append = '';
if ( '18024' == event.detail.contactFormId ) {
for ( var i = 0; i < inputs.length; i++ ) {
if ( 'email-id' == inputs[i].name ) {
email = inputs[i].value;
}
if ( 'first-name' == inputs[i].name ) {
fname = inputs[i].value;
}
if ( 'last-name' == inputs[i].name ) {
lname = inputs[i].value;
}
if ( 'company-name' == inputs[i].name ) {
comp = inputs[i].value;
}
if ( 'text-phone' == inputs[i].name ) {
phone = inputs[i].value;
}
}
append = '&email=' + email + '&firstname=' + fname + '&lastname=' + lname + '&company=' + comp + '&phone=' + phone;
}
if( '20619' == == event.detail.contactFormId ){
if ( 'Email' == inputs[i].name ) {
email = inputs[i].value;
}
append = '&email=' + email;
}
window.location.href = '<?php echo $thankyoulink; ?>'+append;
}
}, false );
</script>
<?php
}
Comments