Jump to content

accept terms before download - module for that?


douglas81
 Share

Recommended Posts

This is not necessarily a PW-specific thing, but I'm trying to work out a way of incorporating this into the PW workflow.

On the backend I'm imagining a repeater field containing a File field and a Text field for T&C. On the front end, I want a site visitor to be able to download that file, but only after ticking a box to say they agree to the T&C. I might also want to ask for a name and/or e-mail address.

It seems like what I want is for the download link to be inoperable unless a checkbox is ticked or form field filled in.

Javascript wouldn't be foolproof enough for this. I'm thinking it basically needs to be a form which redirects (or does some ajax magic), checks if fields are filled in and, if so, creates a one time download link. If not, it simply requests the required fields be filled in fully.

I'm sure this type of thing has been asked before, but I'm struggling to find anything on the forums. Is there a PW module for this functionality?

Any insight appreciated!

Link to comment
Share on other sites

Okay, so here's what I'm thinking...

I'll use Soma's idea and create download files as pages https://processwire.com/talk/topic/4602-flexible-downloads-using-pages/ — thanks again for that link! Then, we'll make sure any page we want to have a download link on uses a template which has a page field where we can select a download page.

Then, to do the "accept terms before download" bit... The php for the page containing the download link will also have a form in it which takes the users name, e-mail address and a checkbox for agreeing to the terms. Hitting the submit button will create a URL POST with name, e-mail, checkbox boolean from the form. That's going to either open up or ajax the Soma-style download page (e.g. file.pdf?agree=true&email=info@mail.com). The associated template php will evaluate that URL (using _GET), and if it's all good, we release the download using:

if($page->pdf){
    wireSendFile($page->pdf->filename);
}

Does that sound like it's gonna work?

Link to comment
Share on other sites

Sounds it's gonna work with wireSendFile you've all possibilties like counting or setting a fieldvalue like mentioned in the comments on soma's original blog....

http://soma.urlich.ch/posts/flexible-downloads-using-pages/

codeexample from soma's comment:

$page->of(false);
$page->counter += 1;
$page->save();
$page->of(true);
wireSendFile($page->pdf->filename, $options);

even you could create your fields on some sort of downloadstats (username, email, checked terms) under a parent page like:

-other pages

--download-stat-home

---download1 (fields: username,date,email,checked terms, witch file/page)

---download2

so you've all options to analyse all downloads...and check if the userentry in the "saved" download-stats page = checked terms true - and then deliver the file.

This is just a mindgame from me - nothing that i build - someone correct me if this could be done in a better way....;)

regards mr-fan

  • Like 1
Link to comment
Share on other sites

...Thats the great thing of this technic.... ;)

The URL = the PAGE

example real world:

your file (page) = link to the file name is www.your-site/downloads/your-file.doc

there you count the download, process the check for an entry or a value, and deliver the file.

Nobody gets the file url in assets!! you asign the assetsfile to a pageurl so the url for the download = the url for the page not the file itself.....

hope i could write it clear?

EDIT: You could even change/update the file without changing the downloadurl

Your have a filepage called "terms" = name of the page with the filefield gets may a terms-2014.pdf in it......next year you could delete the termns-2014.pdf and change it to 2015-terms-new-file.pdf -> the link stays always at your-site/downloads/terms.pdf....

Edited by mr-fan
  • Like 1
Link to comment
Share on other sites

Ah yeah, I see that now.

A follow up question, then...

Obvisouly I'm trying to set this up so that the file is only downloadable if a form has been filled in. As you'll see from the original post, I thought of doing this with some sort of URL POST from the form. But that then gives a URL which somebody could easily share and somebody else could use without going through the original page. (Does that make sense?)

For example, I just did a little test where on submitting the form, we are redirected to this URL website.com/file.pdf?agreed=true and we have this in our PHP...

$agreed = $_GET['agreed'];    
if($agreed == 'true') {

    wireSendFile($page->pdf->filename);
    
} else {

    die("not allowed, sorry");

}

It works great. The only problem is somebody could just copy that link and give it to somebody else. They wouldn't need to go through the original page containing the form.

I wonder if using some sort of "behind the scenes" webhook would be the way to achieve this? I just have no idea how as I've never done something like that before.

Link to comment
Share on other sites

Hey, wait a minute. I'm pretty new to GET and POST and I suddenly realise I've made a huge incorrect assumption! Ha ha. I thought POST and GET were two sides of the same coin. I thought you used POST to "post" the data to the URL string and GET to "get" the data from the URL string. Obviously I'm wrong. Seems like POST appends the data to the http request, right?

So, what I want to do is get the form to $_POST the relevant info. I just don't really know how to do that! Man, now I'm feeling like a total newbie again. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...