WPForms – eBook Download Form

WPForms is great for providing eBook downloads after filling out the form. The simplest way to do it is to include the eBook download link in an email notification. But if you plan to have many eBooks to download, this approach would require a new form for each eBook.

A better way to do this is to use a single form, and store the eBook URL as post meta on the page on which it appears. Then when submitting the form, add that URL to the email.

In your form’s email notification, use {download} where you want the file URL to appear (screenshot). Then create a metabox using CMB2 or ACF that stores the URL as `ea_wpforms_ebook_download_url` meta key. Add the form to the page, and on submission the {download} smart tag in the notification will be replaced with the eBook URL.

* WPForms, eBook Download URL
* @author Bill Erickson
* @see http://www.billerickson.net/code/wpforms-ebook-download-url
function ea_wpforms_ebook_download_url( $string, $form_data = array(), $fields = array(), $entry_id = false ) {
if( ! $entry_id )
$download = get_post_meta( get_the_ID(), 'ea_wpforms_ebook_download_url', true );
if( $download )
$string = str_replace( '{download}', wp_get_attachment_url( $download ), $string );
return $string;
add_filter( 'wpforms_process_smart_tags', 'ea_wpforms_ebook_download_url', 20, 4 );
view raw functions.php hosted with ❤ by GitHub