We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10357
    • 573 Posts
    Hi,

    I need to have a form to capture name, email & company before someone downloads a pdf anywhere on the site.

    Example: http://www.scotlandfoodanddrink.org/insights/publications-/special-reports.aspx#

    Can anyone point me in the right direction on how to achieve this ?

    thanks,
    Gareth
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I would create a custom "Content Type" for PDF files, and use a static resource for the file download.
      http://rtfm.modx.com/display/revolution20/Content+Types
      http://rtfm.modx.com/display/revolution20/Static+Resource

      Then I would have the form, using post-hooks to store and/or email the data, then have the redirectTo resource actually be the static resource.
      http://rtfm.modx.com/display/ADDON/FormIt.Hooks
      http://rtfm.modx.com/display/ADDON/FormIt#FormIt-AvailableProperties

      Now as soon as the form is successfully submitted, the user will get the usual download dialog for the .pdf file. The URL will be to the static resource, not to the file itself, thus providing some protection for your files. They can even be outside of the web root for more serious protection.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 10357
        • 573 Posts
        thank you sottwell, super helpful. My only remaining concern is how to get around asking the user to fill out the form for every pdf download i.e after they have successfully downloaded one.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Ah. That's another matter. Are you referring to a login? Or just being able to download files during that single session?

            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 10357
            • 573 Posts
            A single session would be fine.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              There are several ways to do that. One way would be to set a $_SESSION variable on successful submit with a post hook, and have the redirectTo be a real page with download links, again to static resources with custom content types, and only users with that $_SESSION value set can access the page - almost like a proper "protected" page only without getting into logins and MODx users. These links won't lead to other pages, being custom PDF types, they'll open the download dialog (or open the .pdf file in the browser's PDF reading plugin), while the user will remain on the original page with all the links.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 8822
                • 203 Posts
                Hi, i have used the approach above to allow a user to download T&Cs if they enter their name and email address in a formit form (by redirecting to a static resource referencing a PDF file). This works fine for me in Firefox and IE but does nothing on an ipad/iphone - the PDF is not displayed and the page redirects to my home page (even though the PDF address is given as the URL).

                I found it interesting as well that in Firefox the PDF is displayed to me within the browser but in IE the PDF is displayed in Adobe PDF viewer and not within the browser itself.

                Does anyone know anything about the way Firefox, IE and Safari handle PDFs and why the above may be happening?

                My customer is telling me as well that he is not able to download the T&Cs from IE or Firefox at all. It all seems to be behaving very strangely, but perhaps i am missing something?