[Forminator Pro] Forminator Pro – Download documents

Hi there,

I have a custom post type with posts as documents. A document is attached to that post with a custom field.

Once on the single template of that post there is a Forminator form to request to download that file where you have to fill in your details. Once you have send the form you get a auto reply in your mailbox where I want to add a link to that document.

I don’t want to create one single form for each document since there are a lot. Is there a way to make this dynamic with the URL to the document in the auto reply mail?

Thanks in advance!
Justin

  • Adam Czajczyk
    • Support Gorilla

    Hello Justin

    I hope you’re well today!

    There’s no way out-of-the-box to read the value of some custom field of the post the form is embedded to and then use it in the e-mail notification. There might be a workaround though but that’d depend also on how those download files can be accessed.

    One way would be to use one of built-in notification “placeholders”. Let’s say that, for example, all the files to download are of the same name and are only in different “sub-folders”, like

    /wp-content/uploads/files/20/file.zip
    /wp-content/uploads/files/21/file.zip

    and so on, where the number is equal to the post ID. Then you could most likely “hardcode” such URL in the notification content, replacing the number with

    {embed_id}

    placeholder which would be automatically replaced with the ID of the post/page the form is embedded in (submitted from).

    But if those file URLs are different and/or at different locations and/or with paths/names that do not follow patter and don’t include such ID, it would need some additional custom code to be added to the site so you could actually use some additional custom placeholder in the notification.

    I’ve asked our developers if that’s something that would be doable and relatively simple to do so please keep an eye on this ticket and we’ll update you here once we know more. Please note: our developers’ response time might be a bit longer than ours here on forum as they’re dealing with multiple complex issues. I’d rather also not make promises at this point if we will be able to provide solution as this depends on the complexity of it (so if we’ll be able to provide some simple code snippet or if it will have to be considered a future feature request).

    Best regards,
    Adam

  • Alessandro
    • Nightcrawler & Daydreamer

    Hello Justin.

    I came up with a working snippet to achieve the requested functionality. Add the following code to your theme’s function.php.

    We always recommend to append any snippets in your child’s theme functions.php to allow parent themes to be updated without losing your modifications.

    function wpmudev_forminator_custom_form_mail_admin_message( $message, $custom_form, $data, $entry, $object ){
    	
    	$custom_field  = 'file';
    	$download_link = '';
    	
    	if( ! class_exists( 'ACF' ) ) {
    		return $message;
    	}
    
    	if( get_field( $custom_field, $data['page_id'] ) ){
    		$download_link = get_field( $custom_field, $data['page_id'] );
    	}
    
    	return str_replace( '{download_link}', $download_link, $message ); 
    
    }
    
    add_filter( 'forminator_custom_form_mail_admin_message', 'wpmudev_forminator_custom_form_mail_admin_message', 20, 5 );

    First create a form with some required fields (name, email, etc) and Publish it.

    Then create a user notification which will contain the download link. This can be easily done via Email Notifications > Add email notification.

    In the body section add a {download_link} placeholder to include the post’s custom field file (see attached image).

    Let’s suppose now that you have a post in a custom post type and a file attached to it with field key name “file”.

    Get form’s short-code and add it to the content of your post. Now save it and you are good to go. (See attached response email)

    Note: You have to add to include the short-code to every post you would like to have a form. I assume that you have already registered a custom field (via ACF plugin) or WordPress Core functions. If you are not using ACF we recommend to use get_post_meta() function in the code above to adapt it to your needs.

    Let us know if this worked or if you need further help. :blush:

    Kind regards,
    Alex.