我正在为客户的构建工作,我希望尽可能少地进行更改。抱歉,我对这一切都不太熟悉,我会尽力表明我的立场。
客户端需要提交表单以提示PDF下载。有两个不同的PDF,两个相同形式的实例。填写表单实例1,获取PDF A-表单实例2,PDF B。
下面是这些实例的显示方式:
<div id="whitepaper" class="home_whitepaper_bg w-clearfix">
<?php $lpcnt=0; if(have_rows(\'whitepaper_list\')): ?>
<?php while(have_rows(\'whitepaper_list\')): the_row(); $lpcnt++; ?>
<!-- Making rows for content, looping through and counting loops = lpcnt -->
<!--
... Other content ...
-->
<?php
the_sub_field(\'whitepaper_download_form\');
?>
<?php
$pdf=get_permalink().\'?download=\'.get_sub_field(\'whitepaper_pdf\');
?>
<a data-fancybox data-src="#whitepaper_popup_<?php echo $lpcnt; ?>" data-redirect="<?php echo $pdf; ?>" href="javascript:;" class="whitepaper_download_link w-inline-block w-clearfix">
<!-- Here\'s the buttons for fancybox popups. They use the loop count to build a specific url - this is info I want later! -->
在弹出窗口中:
<div id="whitepaper_popup_<?php echo $lpcnt; ?>" class="whitepaper_popup">
<!-- using that loop count to get a specific div id! -->
<div class="popup_whitepaper">
<div class="whitepaper_form">
<!--
I could put a <?php echo do_shortcode...> here, no?
Their current solution is to grab a javascript code from an ACF field.
I have had a lot of trouble figuring out how to put the CF7 form in that field.
-->
<?php the_sub_field(\'download_form\'); ?>
<div class="w-clearfix"></div>
</div>
<button data-fancybox-close="" class="fancybox-close-small"></button>
<div class="w-clearfix"></div>
</div>
</div>
对。就是这样。然后,使用CF7的新DOM事件,我应该能够设置重定向或simliar?
在函数中。php:
add_action( \'wp_footer\', \'mycustom_wp_footer\' );
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( \'wpcf7mailsent\', function( event ) {
if ( \'FORM ID\' == event.detail.contactFormId ) {
location = <!-- specific url derived from $lpcnt? -->;
}
}, false );
</script>
<?php
}
我不确定自己是否走上了正确的轨道,也不知道如何将正确的URL放入wpcf7mailsent事件侦听器。
SO网友:Maxime Culea
我需要在网站所有案例研究的内容之后添加一个下载CTA,但是;作为交换”;的用户数据:
在您的页面上显示一个CF7表单,我在所有案例研究中都有相同的表单,在内容之后我将其挂接为单一类型,找到一种方法获取想要的PDF url供人们下载,对于我来说,所有案例研究都有不同的PDF,我只是添加了一个ACF字段,仅在PDF上过滤,它返回基于CF7 Dom events, 选择您喜欢的操作以进行下载,因为我不发送任何确认电子邮件,我更喜欢处理wpcf7submit事件。请注意,仅当表单已验证时才会触发wpcf7submit事件,因此代码如下所示:
<?php
// For simplicity, using an anonymous functions
add_action( \'wp_print_footer_scripts\', function () {
// Check the wanted singular post type loading
if ( is_admin() || ! is_singular( \'case-study\' ) ) {
return;
}
// Check if the ACF PDF field is not empty for use
$pdf_link = get_field( \'pdf\' );
if ( empty( $pdf_link ) ) {
return;
}
// Hook on the "wpcf7submit" CF7 Dom event to force the download
printf( "<script>document.addEventListener( \'wpcf7submit\', function( event ) { window.open(\'%s\'); }, false );</script>", $pdf_link );
} );