I want to check if user has downloaded the file so afterwards I will allow him to post a review. To do that I want to flag the node after user download file, flag the node and allow flagged node to be commented. I have a script:

global $user;
$flag = flag_get_flag('downloaded');
$node = node_load(arg(1));
$flag->flag('downloaded', $node->nid, user_load($user->uid), TRUE);

but I don't know how to make that event to occure when clicked on link. Link is in span.file a

Does anybody have an idea how to achieve my goal? I will be so grateful for any answer.

  • Can you elaborate a bit, your title and content says different things. While clicking the link, Do you want to flag a content? or Do you want to show comment form after checking the flag? – wolverine Jun 15 '14 at 5:11
  • Is this private or public link? – jorgetutor Jun 15 '14 at 9:51
  • It is private link which is possible to click on only after purchasing a product. – Michael D Jun 16 '14 at 0:45

If you're using the private file system, you can make use of hook_file_download, it is normally used for granting access but I don't see why not you can use it for flagging stuff.

See an example of this in Example of hook_file_download

If you're using the public one, it will be way trickier, you're going to need to wrap the download link to react with your custom code, this could be done by replacing the download link like the Public Download Count module does, or providing your own hook_menu callback that is called via ajax to flag the content, but then you depend on whether the user has js enabled or not.

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.