Contact Form 7 Redirect on Submit 以及是否检查了第一个无线电

Contact Form 7 Redirect on Submit and if the first radio is checked

我们最喜欢 CF7 表格 http://prntscr.com/v3ijfm, http://prntscr.com/v3ilpi。 网站 url:https://loyard.it/

任务:

如果单击第一个单选按钮并提交表单,将用户重定向到 url。

对于其他 2 个单选按钮,插件处理任务(在成功付款后用户被重定向)。

我在 functions.php 中插入了 js,但它不起作用。

add_action('wp_footer', 'redirect_cf7');

function redirect_cf7()
{
    ?>
<script>
document.addEventListener('wpcf7mailsent', function(event) {
    $('#PayMeth input[name="radio-809"]').change(
        function() {
            if (this.checked && this.value == 'Paga alla consegna') {
                location = 'https://www.google.md/';
            }
        });
}, false);
</script>

有什么建议吗?提前致谢!

更新:这有效,但问题是它也为其他 2 个单选按钮重定向(

<script>
    $('body #PayMeth input[name="radio-809"][value="Paga alla consegna"]').attr('checked', true).change(
        document.addEventListener('wpcf7mailsent', function(event) {
            window.location.href = 'https://loyard.it/thank-you/';
        }, false));
    </script>

换行

$('#PayMeth input[name="radio-809"]').change(

$('body #PayMeth input[name="radio-809"]').change(

f***ck 这个 jQuery :P 对我来说这个更干净

const redirect = () => {
   window.location.href = 'https://loyard.it/thank-you/';
};

const input = document.querySelector(`body #PayMeth input[name="radio-809"][value="Paga alla consegna"]`);
//console.log(input) - check that your selector works correctly
if(input){
  input.addEventListener("change", (event) => {
    if(event.target.value){
      document.addEventListener('wpcf7mailsent', redirect);
    } else {
      document.removeEventListener('wpcf7mailsent', redirect);
    }
  })
}