0

In the Drupal site I'm setting up, there's a Download page containing several links to download softwares.

  1. What is the best way to "bind" the softwares to the page, put them anywhere online and place a direct link in the page?

  2. Does anyone know a module that would show a contact form when a user clicks one of the "Download" buttons, preventing him from downloading unless he properly completes the form? Our goal is to receive the contact information of any person downloading our software.

2

There is Webform Protected Downloads. But it will result to quite a different structure from yours. Webform Protected Downloads allows someone to download a "protected" file after filling out a webform. You can add more than one file and have the download links expire after a certain time.

When also looking for something like your issue I also found another module (don't remember the name) that added a page before redirecting you to a node. So maybe you could add a webform page to send the user before reaching the download page. But if he knows the link he could bypass it of course.

  • any working example to use the Webform Protected Downloads module? – AshwinP Nov 27 '13 at 14:03
  • If you want to see it working, besides setting it up on your Drupal installation and running it, there is also a demonstration site set up by the developer. From the module page: blog.dev030.com/demos/webform-protected-downloads – Perisdr Nov 28 '13 at 15:31
  • My flow is like that. 1. I have scrollable list of download links for Private files. 2. When user click on Download File link it will show Form to gether some data like first_name, last_name, email and Phone. 3. after submission Link will be forward to email Id specified in form with KEY will check Once download the file link will be expire. 4. Second Mail goes to admin and Data will be stored to system as Sales Lead. 5. File will be get to User. – AshwinP Nov 29 '13 at 4:00
2

I created a module named jhmodule to handle the form submission and set session for a user, code is as follows

    <?php
//hook menu to handle form 
function jhmodule_menu() {
    $items['downloads/pdf'] = array(
        'title' => 'Form submit',
        'page callback' => 'send_link',
        'access callback' => TRUE,
    );
    return $items;
}

function send_link(){
   if(isset($_SESSION['pdf_download_session'])){
       $pdf_download_session = set_session_for_download($_POST);
        $out = json_encode($pdf_download_session);
   }  else {
        $pdf_download_session = set_session_for_download($_POST);
    $out = json_encode($pdf_download_session); 
}
    $clean_file_name = rawurlencode($_POST['file_name']);
    $out = json_encode('/sites/default/files/'.$clean_file_name);
  print $out;
    return ;
}

function set_session_for_download($argument_a){
    if(!isset($_SESSION['pdf_download_session']))
    {
    $_SESSION['pdf_download_session'] = array('fname'=> $argument_a['fname'], 'lname'=> $argument_a['lname'], 'new'=>'yes');
    $pdf_download_session =  $_SESSION['pdf_download_session'];
    }  else {
         $pdf_download_session =  $_SESSION['pdf_download_session'];
    }
return json_encode($pdf_download_session) ;
}

In page--contentType.tpl.php link to the form and checking if the session is set if the session is set jquery adds path to the filename:

//node--contentType.tpl.php
<span rel="#pdf_form" class="download_link download_link_one"><a file_name="<?php
        if (isset($content['field_application_sf_download']['#items'][0]['filename'])) {
            print $content['field_application_sf_download']['#items'][0]['filename'];
        }
        ?>" href=""><img src="/sites/all/themes/jhtheme/images/whitepaper_btn.png"/></a></span>

//page--contentType.tpl.php
<form action="downloads/pdf" method="POST">

    <input type=hidden name="oid" value="test">
    <input type=hidden name="retURL" value="http://**Insert Thank You Page Address Here**">
    <div class="form-sections-holder">

        <div class="frame">

            <div class="form-left-content"> <p class="formTitle">Lorem Ipsum sit dolor</p>

                <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In posuere felis nec tortor. Pellentesque faucibus. Ut accumsan ultricies elit. Maecenas at justo id velit placerat molestie.</p>

                <p>Donec dictum lectus non odio. Cras a ante vitae enim iaculis aliquam.</p>

            </div>

            <div class="form-right-content">

                <div class="row">

                    <div class="text">

                        <input type="text"  name="first_name" id="first_name" value="First Name" />

                    </div>

                    <div class="text">

                        <input type="text"  name="last_name" id="last_name" value="Last Name" />

                    </div>

                </div>

                <div class="row">

                    <div class="text">

                        <input type="text"  name="email" id="email" value="Email" />

                    </div>

                    <div class="text">

                        <input type="text"  name="company" id="company" value="Company" />

                    </div>

                </div>

                <div class="row">

                    <div class="text">

                        <input type="text"  name="city" id="city" value="City" />

                    </div>

                    <div class="text">

                        <input type="text"  name="state" id="state" value="State / Province" />

                    </div>

                </div>

                <div class="row">

                    <input class="submit" type="image" value="Submit" alt="Submit" src="/sites/all/themes/jhtheme/images/submit.png">

                </div>

            </div>

        </div>

    </div>

</form>
 <?php
            if (isset($_SESSION['pdf_download_session'])) {
                print '<div id="pdf_download_session"></div>';
            }
            ?>

JQuery to handle the form submission.

    //download link for pdf
jQuery('.download_link').click(function(){
    if(jQuery('#pdf_download_session').length >0){
        var file_name = jQuery('.download_link a').attr('file_name');
        jQuery('.download_link a').attr('href', '/sites/default/files/' + file_name);
        return true;
    }else
    {
        jQuery('#pdf_form, #fader_wrapper').show();
        //form overlay 
        jQuery("span[rel]").overlay();
        jQuery('#pdf_form a.close').click(function(){
            jQuery('#pdf_form, #fader_wrapper').fadeOut(100);;
        });
    }
    return false;  
});
//form validation
jQuery('#pdf_form').find('input').blur(function(){
    var blur_element = jQuery(this);
    if(blur_element.val().length == 0 ){
        jQuery(this).addClass('form_warning');
    }
});
jQuery('#pdf_form').find('form').submit(function(){
    var fields = {
        first_name: jQuery('#first_name').val(),
        last_name: jQuery('#last_name').val(),
        email: jQuery('#email').val(),
        company: jQuery('#company').val(),
        city: jQuery('#city').val(),
        state: jQuery('#state').val(),
        file_name: jQuery('.download_link a').attr('file_name')
    }
    jQuery.ajax({  
        type: "POST",  
        url: '/downloads/pdf',
        data: fields,
        dataType: 'json',
        success: function(pdf_location) {  
            jQuery('#pdf_form').hide();
            jQuery('.ad-block .frame').append('<div id="pdf_download_session"></div>');
            window.location = pdf_location ;




        }
    });
    return false;
});

Later on as I get more time I will try to explain each step more. In my case form data was going to be handled by third party application that is the reason I am doing every thing manually. You should think about using drupal's form api.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.