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
  * @link 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 )
        return;
    $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 );

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk