Hi,

I'm trying to make a basic download counter work. Right now it kinda works, but I'm facing 2 issues.

This is my code:
snippets/download-counter.php
Code: Select all
<cms:php>
   $GLOBALS['template_name'] = $_GET['p1'];
   $GLOBALS['page_id'] = $_GET['p2'];
</cms:php>
<!--
<cms:php>
   echo "template name: ".$GLOBALS['template_name'];
   echo "".$GLOBALS['page_id'];
</cms:php>-->

<cms:db_persist
   _masterpage= $GLOBALS['template_name'];
   _page_id= $GLOBALS['page_id'];
   _mode='edit'
   
   page_downloads="<cms:add page_downloads '1' />"
/>


And this is my jQuery:
Code: Select all
$('.download-button').click((event) => {
   let target = $(event.target),
        t_name: string = target.data("t-name"),
          p_id: string = target.data("p-id"),
        counterURL = "/download.php?p1=" + t_name + "&p2=" + p_id;

   this.ajaxRequest(counterURL);
})

ajaxRequest(url: string): void {
   $.post(url, (res) => {
      console.log("call went through");
      console.log(res);
   });
}


The issues I'm facing are:

1. Currently I'm using static data to increase the downloads field for each item. So instead of
Code: Select all
_masterpage= $GLOBALS['template_name'];
_page_id= $GLOBALS['page_id'];

(which is how the final code is supposed to be I think) I'm actually passing
Code: Select all
_masterpage= 'index.php';
_page_id= 67;

This is because I get 'ERROR: Tag "db_persist" - _masterpage does not exist' (data bound forms is uncommented in kfunctions.php). I'm pretty sure that it's because of the way I'm passing the variables to the db_persist tag.

2. Second issue: as I said, right now I'm using dummy data, so it (kinda) works. The problem is that the page_downloads field only goes from 0 to 1, and no more than that.

It might be that I'm missing something (or a lot of things). Can anyone give some feedback?

Thanks!

Note: '/downloads.php' is a file in the root of the project. All it does is embed the 'download-counter.php' snippet.