3 Replies Latest reply on Mar 8, 2008 3:57 AM by Günter Schenk

    Create Custom Trigger to Download File after Captcha in Form

      I am trying to create a form (needs to be a form) that baasically has two elements: one is the captcha image/field, and the other is a Submit Button labelled as "Download File". The objective is to require processing of captcha before the execution of the Download File. The file's filename is from Mysql DB. I think the best way is to create a custom form, with the associated custom trigger.

      What I have no idea of how to do is to make the $downloadObj be ten trigger. ie. I need to create a custom trigger for file download, and then I need to Register the Trigger so it executes AFTER the captcha is validated.

      THANKS!!!
        • 1. Re: Create Custom Trigger to Download File after Captcha in Form
          Günter Schenk Level 4
          Hi Max,

          -----
          and then I need to Register the Trigger so it executes AFTER the captcha is validated.
          -----

          will setting the Custom Trigger to END help ?

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: Create Custom Trigger to Download File after Captcha in Form
            Level 1
            Hi Günter: actually, no. Perhaps if I explain in greater detail what I am trying to accomplish:

            1) I have a document repository. From a list of documents, you can click on a button to see the full document details, and to download it if so desired.

            2) In this docdetail page (lets call it that), you basically have all the info pertaining to the document (i.e. document title, filename, size, extension, summary of contents, author, etc.

            Here, the user can then opt to download the document by clicking on a link, created with the ADDT File download behavior.

            So I have this now as part of my code:

            // Download File downloadObj1
            $downloadObj1 = new tNG_Download("", "KT_download1");
            $downloadObj1->setConnection($conn_docs, "docs");
            // Download Counter
            $downloadObj1->setTable("jos_docmax_documento");
            $downloadObj1->setPrimaryKey("id_documento", "NUMERIC_TYPE", "{GET.id_documento}");
            $downloadObj1->setCounterField("dwn");
            // Execute
            $downloadObj1->setFolder("filedirectory/");
            $downloadObj1->setRenameRule("{docdetail.filename}");
            $downloadObj1->Execute();

            An I also have a download link that executes the above as follows:

            <a href="<?php echo $downloadObj1->getDownloadLink(); ?>" class="Adocbutton">Download Document</a>.

            In my opinion, this is just fine, but my client wants to add a captcha verification for a user to be able to download the file rather than just letting him click on the above link.

            Now, since I cant add a captcha unless its related to a form with an Insert or Update transaction, I followed your advice and created a quick form which updates to a dummy table, that was simple enough, and to this form I added the captcha, also simple enough, and now I have a transaction to which I can associate a custom trigger for the download.

            Now the part that has been hard for me, not being at all familiar with how ADDT "language" (if I may call it that) works (although oftentimes it is not so hard to figure out), I tried to covert the downloadObj code into a trigger as follows:

            //start Trigger_DOWNLOAD trigger
            function Trigger_DOWNLOAD(&$tNG) {
            // Download File downloadObj1
            $downloadObj1 = new tNG_Download("", "KT_Update1");
            $downloadObj1->setConnection($conn_docs, "docs");
            // Download Counter
            $downloadObj1->setTable("jos_docmax_documento");
            $downloadObj1->setPrimaryKey("id_documento", "NUMERIC_TYPE", "{GET.id_documento}");
            $downloadObj1->setCounterField("dwn");
            // Execute
            $downloadObj1->setFolder("docsmax/");
            $downloadObj1->setRenameRule("{docdetail.filename}");
            $downloadObj1->Execute();
            }
            //end Trigger_DOWNLOAD trigger

            Where "KT_Update1" is the referencce to the form submit button. It becomes quite clear that there is something missing that I have not included above, and that is the code that generates the link (i.e. "$downloadObj1->getDownloadLink()"). Anyway, I believe the above is probably wrong, incomplete, or both.

            With this trigger, I then added a custom-trigger to the update transaction, also not too difficult. The result looks like this:

            // Make an update transaction instance
            $upd_jos_docmax_dummytable = new tNG_update($conn_docs);
            $tNGs->addTransaction($upd_jos_docmax_dummytable);
            // Register triggers
            $upd_jos_docmax_dummytable->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
            $upd_jos_docmax_dummytable->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
            $upd_jos_docmax_dummytable->registerTrigger("BEFORE", "CheckCaptcha", 10);
            $upd_jos_docmax_dummytable->registerTrigger("AFTER", "Trigger_DOWNLOAD", 98);
            // Add columns
            $upd_jos_docmax_dummytable->setTable("jos_docmax_dummytable");
            $upd_jos_docmax_dummytable->addColumn("dummydata", "STRING_TYPE", "POST", "dummydata");
            $upd_jos_docmax_dummytable->setPrimaryKey("id_dummytable", "NUMERIC_TYPE", "VALUE", "1");


            Where I have inserted my custom trigger "trigger_DONWLOAD" as AFTER with prority 98. Of course everything "works", I mean the dummytable is updated, the captcha is checked (and stops the process if the text is not the same as the image), but no download is initiated. Note also that I dont want to redirect after the download, I just want the file to download while the user remains on the same page.

            I have also tried some variations on the above. I did set the trigger as an END and not an AFTER, with the same results. I then tried to add a redirect to the transaction where the URL to go to was a variable, say $downloadlink, and where I had tried to say via PHP that
            $downloadlink = $downloadObj1->getDownloadLink(); but of course it doesnt quite work (I just get an empty variable).

            I may be wrong, but I think the form, update transaction and execution of the triggers are working, and that the specific ccustom trigger "trigger_DOWNLOAD" is not right.

            I really appreciate your time in responding once already, and would be really grateful if you could give me some additional help on this.

            Thanks!!
            • 3. Re: Create Custom Trigger to Download File after Captcha in Form
              Günter Schenk Level 4
              Hi Max,

              as long as the $downloadObj1->getDownloadLink() isn´t attached to an existing link (or maybe some form action, who knows), your custom application won´t know what to do.

              I personally don´t know *if* it´s possible at all to encapsulate one of the provided ADDT triggers (in this case the Download trigger) within a Custom Trigger, or if ADDT expects that to be separated from each other.

              ------
              Note also that I dont want to redirect after the download, I just want the file to download while the user remains on the same page.
              ------

              if this pretty experimental approach doesn´t work, you might indeed consider to provide the download functionality on the "redirect after insert" page -- and in order to "protect" that page, you could add a static variable to the "redirect after insert" link (in addition to the {GET.id_documento} variable of course) like e.g. "download_allowed = Y", which in turn allows you show/hide the download link if that variable isn´t set.

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver