Simple Solution to collect email addresses using Contact Form 7 "Form"
- Create a form using contact form 7.
- Put the PDF file in the WordPress media library and replace the PDF location in the code below with your website PDF location
- Replace 147 with your contact form ID
- Give it a file name
- Copy and paste the code into the WordPress Code Snippet plugin, make sure to exclude <?php from the below code when you use Code Snippet plugin
<?php
add_action( 'wp_footer', 'add_download_pdf_file' );
function add_download_pdf_file()
{
$pdf_url = 'https://www.onemcoprojects.com.au/wp-content/uploads/Sample.pdf';
$contactform_id = (int) 147;
$filename = 'ONEMCO-YourDigitalTeam';
?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event )
{
if ( <?php echo $contactform_id;?> == event.detail.contactFormId )
{
jQuery('body').append('<a id="cf7fd-attachment-link" href="<?php echo $pdf_url; ?>" target="_blank" download="<?php echo $filename; ?>"></a>');
jQuery('#cf7fd-attachment-link')[0].click();
setTimeout(function()
{
jQuery('#cf7fd-attachment-link').remove();
},2000);
}
}, false );
</script>
<?php
}
?>