5 Replies Latest reply on Sep 8, 2008 3:05 PM by (shane_mosier)

    custom trigger in case of upload error

      any help or examples available?
      The documentation on addt is really poor.
      What I want to do is redirect on a specific page the user in case of error, or performing a specific task.
      Can you suggest me any resources?

      Thanks
        • 1. Re: custom trigger in case of upload error
          Fonzie,

          You can do this in a Custom Trigger to redirect:

          header("Location: http://www.example.com/");
          exit;

          I do this quite frequently. So in a Custom Trigger, I might have something like:

          if($thisValue == $newValue) {

          header("Location: error_page.php");
          exit;

          }

          Shane
          • 2. Re: custom trigger in case of upload error
            Level 1
            Please Shane, a bit more!
            Where do I add this code?
            How do I wrap the function?
            What do I add visually into the server behaviours? The naming convention?

            Thanks
            • 3. Re: custom trigger in case of upload error
              Level 1
              Fonzie,

              You would add the Custom Trigger server behavior. Under the Developer Toolbox>Forms>Custom Trigger.

              The Custom Trigger Wizard has 2 tabs, Basic and Advanced. I usually leave the box in the basic tab blank. You can add your php code here, but I prefer to add my Custom Trigger code to the Dreamweaver Code View directly.

              The Advanced Tab allows you to name your Trigger/function and you can set the execution order. Trigger's are registered to transactions Update, Insert, and/or Delete. You specify wether you want the Trigger to execute BEFORE or AFTER the Update/Insert/Delete transaction. By default this is set to AFTER.

              Priority allows you to control execution order of the transactions and triggers. You can have multiple triggers and control the order they execute.

              So I usually start the Custom Trigger Wizard and go right to the Advanced tab. I name my Trigger, and set the execution order. Then I close the Wizard. Then I go to the Dreamweaver Code View, and you will see something like this:

              //start Trigger_Custom trigger
              function Trigger_Custom(&$tNG) {

              }
              //end Trigger_Custom trigger

              Add your code between the { } and add

              header("Location: error_page.php");
              exit;

              for the redirecting.

              Shane
              • 4. Re: custom trigger in case of upload error
                Level 1
                And now last one! Which are the part of that HUGE object called $tNG that allows me to understand that there is an error in course? Like a bad file extension or an exceeded filesize?

                I have tried:
                function Trigger_Custom(&$tNG) {
                $ginotronic=$tNG->getError();
                $pincopalla=$tNG->getErrorMsg();
                print "error:";
                print_r($ginotronic);
                print "errormsg:";
                print_r($pincopalla);
                die("i am dead in name of debugging");

                }

                But I get nothing on $tNG->getError() and an empty three values array on $tNG->getErrorMsg()

                This in both cases... or the upload is successfull or I'm uploadinf for ex a file with wrong extension.
                • 5. Re: custom trigger in case of upload error
                  Level 1
                  Fonzie,

                  Here's the code you use to throw an ADDT error in a Custom Trigger:

                  $myError = new tNG_error("This is my error text."); return $myError;

                  So you would do something like this in your Custom Trigger:

                  if(a != b) {

                  $myError = new tNG_error("Values are not equal."); return $myError;

                  }

                  Shane