• Resolved dedrago

    (@dedrago)


    Hi! First of all, this is the greatest contact form plugin! Thank you!
    I have a question. How could I redirect to a thank you page using queries in target URL.
    E.g. I have a form which sends field to the endpoint, than I receive an id which returns by function in functions.php. So, basically i need to redirect the page with the form to https://www.example.com/thank-you?user_id=$ifs_id which outputs https://www.example.com/thank-you?user_id=4555454 for example. Maybe there is a way to pass this variable to js? On the other hand wp_redirect can do the trick but I assume it’s not possible in wpcf7_mail_sent hook.

Viewing 1 replies (of 1 total)
  • Thread Starter dedrago

    (@dedrago)

    To do ridirect with dynamic variables, please use cookies.
    So, before return, use
    setcookie("id", $id, time() + 60*60*24*30, '/');
    Create function after that

    function getCookie(name) {
      var matches = document.cookie.match(new RegExp(
        "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
      ));
      return matches ? decodeURIComponent(matches[1]) : undefined;
    }
    document.addEventListener( 'wpcf7mailsent', function( event ) {
        location = 'https://www.example.com/&u_id=' + getCookie('ifs_id');
    }, false );
    </script>
    
    <?php
    }
    add_action( 'wp_footer', 'vc_dom_event_footer' );
Viewing 1 replies (of 1 total)
  • The topic ‘wp_redirect doesn’t work’ is closed to new replies.