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

    I have a quick question.

    1. I have some downloadable files
    2. I want to have a form, which you fill in
    3. The form sends you an email thank you message with a direct link to the file you wanted to download.

    I can use eform for step 2, but how do I know which file to send?

    Is there a plug-in/module, etc that helps facilitate the process of selecting a file to download then sending the user a direct link to the user’s email address?

    Many thanks.
      • 32645
      • 377 Posts
      Maybe if I make it easier to understand I can get a quick answer.

      On the site you have downloadable PDFs (assets/files/somefile.pdf)

      The site lists them somewhere.

      Before you can download the file you must fill in a form, the form asks for your name and email.

      An email message is sent to you, firstly thanking you for your request and providing you a hyperlink to where you can download the file.

      How does one achieve these goals?
        • 21496
        • 225 Posts
        nightsignals Reply #3, 19 years ago
        If your users are allowed to download any file once they filled in the form, maybe you could setup a page and use the FileDownload snippet http://www.modxcms.com/FileDownload-502.html. Then you simply send them a link to that page with eForm. Or even easier, you redirect to that page after successfully submitting the form.
          René
          • 7455
          • 2,204 Posts
          1. you could use multiple eform calls with differed report chunks with a link in them
          2. you could use an eform event to insert the link into the report.
          3. you could use a puldown menu to select the file and then the link would be the value (not really secure)
          For this is modx there are 100 more options to do this.
            follow me on twitter: @dimmy01
            • 3749
            • 24,544 Posts
            Quote from: worchyld at Sep 29, 2007, 02:03 PM

            Maybe if I make it easier to understand I can get a quick answer.

            On the site you have downloadable PDFs (assets/files/somefile.pdf)

            The site lists them somewhere.

            Before you can download the file you must fill in a form, the form asks for your name and email.

            An email message is sent to you, firstly thanking you for your request and providing you a hyperlink to where you can download the file.

            How does one achieve these goals?

            As Dimmy says, MODx provides many ways to do this. For me, the fastest would be to put a drop-down list of the available files on your form and then write a short PHP function to turn that into a URL string to be placed in the content of the email you send them. Someone more familiar with eForm might use eForm instead.

            The PHP function could be a snippet, or it could just be dropped into the code that sends the email.

            Bob


              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 27708 MODX Staff
              • 2,502 Posts
              I have done this before without MODx and in those cases I would use a form on the file’s page. So if your visitor was on Property Page create a form as the following:
              <form action="eformaction" method="post" accept-charset="utf-8">
              	<p> <input type="hidden" name="property_pdf" value="property_pdf" id="some_name"></p>
              	<p><input type="submit" value="Download File"></p>
              </form>
              


              Submit should send the user to the eForm page where the hidden value then gets appended to the file location.

              You will have to use sessions to do this but it works well.

              I do this on sites that use common form elements and return specific form fields based on user inputs so I don’t have to write code over and over again.

              The problem is that I am not sure how to do this with eForm. If I hadn’t had a Dortmunder already I would be able to figure this out much better.

              Hope this sends you in the right direction. If not I will do it on my def install on my localhost and test it.

              All the best,

              Jay

              [Update!:] I thought about this some more and looked at eForm again and what I would do is place an eForm call in each page for each document and use a report template with the link to the file.
                Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                • 30223
                • 1,010 Posts
                There are as has been said many ways to achieve this in modx. Here’s one possible solution.

                Suppose you have a page with all your download links. The links in this case all point to your form and use the base name of your pdf files as the file id. So assets/files/somefile.pdf would become:

                <a href="downloadform.html?file_id=somefile">Some File</a>
                



                In your eForm form template you need to have a hidden field for the file id so it can propagate through the process.
                <input type="hidden" name="file_id" value="[+file_id+]" />
                


                In your eForm call you add the eFormOnBeforeParse and the eFormOnBeforeMailSent events with the below functions.You also need to store the below event functions in a separate snippet and add the snippet to the form page just before the eForm snippet call.

                [[eFormEventFunctions]]
                [!eForm? &eFormOnBeforeParse=`onBeforeParseFunction` &eFormOnBeforeMailSent=`onBeforeMailSentFunction` ... ret of params ]]
                


                The functions for ’eFormEventFunctions’ snuippet:

                <?php
                function onBeforeParseFunction(&$fields,&$templates){
                   global $modx;
                   #If no file is selected redirect to another page (with download links?) 
                   $pageId = 1; //change to id of whatever page you want to redirect to.
                   if(!isset($_REQUEST['file_id'])){ 
                      $modx->sendRedirect($modx->makeUrl($pageId));
                      return false;
                   }else{
                      #store file_id in form so it propagates
                      $templates['tpl'] = str_replace('[+file_id+]',$_REQUEST['file_id'],$templates['tpl']);
                      return true; //process normally
                   }
                }
                
                function onBeforeMailSentFunction(&$fields){
                   #is called when form is submitted succesfully
                   #file_id should now be in the fields array
                   $file = 'files/'.$fields['file_id'].'.pdf';
                   #check that file exists
                   if(!file_exists($modx->config['rb_base_dir']).$file){
                      $fields['validationmessage']='The file you requested does not or no longer exists!';
                      return false;
                   }else{
                      #Get the url belonging to file_id and store in fields array
                      # In your report template place a [+download_url+] place holder
                      $url = $modx->config['rb_base_url'] . 'files/'.$fields['file_id'].'.pdf';
                      $fields['download_url'] = $url;
                      return true;
                   }
                }
                ?>
                


                None of this has been tested. I leave that up to you. It should give you one idea (out of many possibilities) on how to solve your problem.

                  • 32645
                  • 377 Posts
                  This is great!

                  Thank you so much for all your help! I really appreciate it!

                  Thanks again! *tips hat*
                    • 32645
                    • 377 Posts
                    Hi TobyL,

                    I’m using your code, but I’m having problems -- it’s not getting the file and putting into any fields.

                    The page is blank and just has this in it;

                    // This is what appears on the page template
                                 [[eFormEventFunctions]]
                                 [!eForm? &eFormOnBeforeParse=`onBeforeParseFunction` &eFormOnBeforeMailSent=`onBeforeMailSentFunction` &formid=`downloads_form` &tpl=`downloads_form`!]
                    


                    The actual hyperlink is like this;

                    // Downloads is a page
                    // press release is a PDF
                    <a href="/downloads?file_id=Press_release">Some File</a>
                    


                    The functions are the same as yours.

                    The page chunk "downloads_form" is like this.

                    // Downloads form chunk
                    
                    <form method="post" action="/[~[*id*]~]" id="form">
                    
                    <input type="text" name="file_id" value="[+file_id+]" /> <!-- it should put the value of the file in here, but it doesn't display anything -->
                    <input type="hidden" name="formid" value="download_form" />  
                    
                    </form>
                    


                    The problem is, its not retrieving anything from either the GET/REQUEST.

                    I’ve tried outputting it, buts its always blank, I don’t know why its not returning anything.

                    I should point out that I’ve got friendly urls on, but even with them off, it still returns nothing in either the get or request.

                    I’m going to try and switch off htaccess and see what happens -- but assuming that isn’t the problem, is there something else I’m doing wrong?

                    !Edit: I got rid of htaccess, but it still does not pass the file_id at all...
                      • 32645
                      • 377 Posts
                      Okay, here’s an update -- I think there’s a problem with $template (or $templates).

                      I outputted the $_REQUEST *before* my eform -- and it succesfully outputs the file I chose, proving that GET is working and that it is sending the right details.

                      After this output I put another snippet outputting the contents of $template, $fields, etc -- but there’s nothing there -- this leads me to think that $templates isn’t right -- or that $templates is inaccessibile or that it was blanked.

                      In summary,

                      [[testy]]  // force output the $REQUEST 
                      [[eFormEventFunctions]]  // do the functions
                      [[testy2]] // force output the contents of $templates, $fields, etc.
                      [!eForm? stuff... !]
                      


                      The force output is like this;

                      <?php
                      print "<br />TEMPLATE DATA: " . $templates;
                      print_r($templates);
                      print '<br />';
                      print "<br />TEMPLATE DATA2: " . $template;
                      print_r($template);
                      print '<br />';
                      print "FIELDS: ".  $fields;
                      print_r($fields);
                      ?>
                      


                      All of this is blank... which means that it never sets $file_id in my form. Question is, how do I remedy it?