Redirecting user to a dynamic download page after form submission

Hi guys,
here is a scenario we are trying to setup. We have a website with woocommerce installed. All products have a pdf file attachment field made with ACF. Its called “product_pdf”.
All products have a “Enquire Now” button that triggers a pop up form, where users have to fill up details and then submit.

What we need is, upon form submission users should be redirected to a thank you page, that has “download pdf” button. The pdf file should be the same as attached with the product. So basically it should change according to the product from where the user was sent to download page.

Any help in this regards is greatly appreciated.

I would suggest you add a url-parameter to your Custom redirect URL Controls inside the form-element.

this could look something like this:
https://your-site.com/thank-you/?download-pdf={post_id}

Now you have a dynamic url-parameter that contains the current-post / product id.

from here, you could either create a custom dynamic-data-tag that returns the acf-value depending on the url-parameter, or wrap the download-button in a custom query (PHP query editor), that takes the post_id and queries for only this post. Then you could just use the standard acf-field-dynamic-data-tag inside the button.

Both solutions should work and it’s up to preference. The ladder might be easier and could look something like this (PHP query editor):

$post_id = $_GET['download-pdf'] ?? 0;

$args = [
  'post_type' => 'product',
  'posts_per_page' => 1,
  'post__in' => [$post_id],
];

return $args;

Hi SuatB, first thank you for taking your time out and responding to my query. Here is what i did -

  1. Created a dynamic url paramter — https://your-site.com/thank-you/?download-pdf={post_id}

  2. Added this code to my functions.php file in bricks child theme-
    3.----> add_filter(‘bricks/dynamic_data’, function ($value, $tag) {
    // Check if the dynamic data tag is “custom_product_pdf”
    if ($tag === ‘custom_product_pdf’) {
    // Check if the URL has the “download-pdf” parameter
    if (isset($_GET[‘download-pdf’])) {
    $product_id = intval($_GET[‘download-pdf’]); // Get the product ID from the URL

         // Fetch the ACF field value (replace 'product_pdf' with your actual ACF field name)
         $pdf_url = get_field('product_pdf', $product_id);
    
         // Validate and return the PDF URL
         if ($pdf_url && filter_var($pdf_url, FILTER_VALIDATE_URL)) {
             $value = $pdf_url;
         } else {
             $value = ''; // Return empty if no valid URL is found
         }
     } else {
         $value = ''; // Return empty if no product ID is found
     }
    

    }
    return $value;
    }, 10, 2);

  3. Added a download button to my thank you page - with dynamic link → {{ custom_product_pdf }}

  4. when tested, the form redirects with the product id in the url, but the download button fails to render actual pdf link but instead show href=“{{ custom_product_pdf }}” instead.

What am i doing wrong here ?

I don’t know where you got this filter-name from, but this doesn’t exist.
To create a dynamic-data-tag, you need to first register it:

add_filter('bricks/dynamic_tags_list', function ($tags) {
  $tags[] = [
    'name'  => '{custom_prdouct_pdf}',
    'label' => 'Custom Product PDF',
    'group' => 'My Dynamic Data Group', // Change to your Liking
  ];
  return $tags;
});

After that we have to write some logic. In your case we need to use these two filters:

add_filter('bricks/dynamic_data/render_content', 'prexix_render_custom_product_pdf', 20, 3);
add_filter('bricks/frontend/render_data', 'prexix_render_custom_product_pdf', 20, 2);
function prexix_render_custom_product_pdf($content, $post, $context = 'text')
{

  if (strpos($content, '{custom_product_pdf}') === false) return $content;

  $value = '';

  if (isset($_GET['download - pdf'])) {
    $product_id = intval($_GET['download - pdf']);

    $pdf_url = get_field('product_pdf', $product_id);

    if ($pdf_url && filter_var($pdf_url, FILTER_VALIDATE_URL)) {
      $value = $pdf_url;
    }
  }

  $content = str_replace('{custom_product_pdf}', $value, $content);

  return $content;
}

This code was not tested, but should work from what I imagine.

And remember to use dynamic data with only one bracket on each side {custom_product_pdf}.

Cheers Suat