17 Replies Latest reply on May 13, 2008 6:04 PM by (Jeremy_Horowitz)

    redirect option based on user selection

    Level 1
      I have a form where a user can choose 1 of 2 options. I would like the form to direct to one page if the user chooses 1 and another if the user chooses 2. We experimented with some if code, and it worked but it forced ADDT to no longer read the insert trigger, which we need so we can add a send email trigger. Is there a way of still sending and email? either by getting the insert trigger to recognize the if statements or another method? Thanks in advance for the help.
        • 1. Re: redirect option based on user selection
          Günter Schenk Level 4
          Hi Jeremy,

          ----
          We experimented with some if code
          ----

          could you post that code here, and including the surrounding lines in order to see the context ?

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: redirect option based on user selection
            Level 1
            Hi Günter

            Here you go (and thanks for the quick reponse):
            // Make an insert transaction instance
            $ins_journalad_ad = new tNG_insert($conn_connAdmin);
            $tNGs->addTransaction($ins_journalad_ad);
            // Register triggers
            $ins_journalad_ad->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
            $ins_journalad_ad->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);

            // Redirect to thankyou.php page only if the payment method is with check
            if($_POST['paymethod']==2)
            {
            $ins_journalad_ad->registerTrigger("END", "Trigger_Default_Redirect", 99, "thankyou.php?id_ad={id_ad}");
            }

            // Redirect to Google Checkout -> payment_card.php
            if($_POST['paymethod']==1)
            {
            $ins_journalad_ad->registerTrigger("END", "Trigger_Default_Redirect", 99, "payment_card.php?id_ad={id_ad}&PHPSESSID=".session_id());
            }
            // Add columns
            • 3. Re: redirect option based on user selection
              Günter Schenk Level 4
              Hi Jeremy,

              to my knowledge ADDT can´t grab the form values in here using the standard PHP $_POST['whatever'] syntax -- but it *might* work when using ADDT´s $tNG->getColumnValue("paymethod") transaction value syntax instead.

              Can you please try and see if the following works ?

              // Redirect to thankyou.php page only if the payment method is with check
              if($tNG->getColumnValue("paymethod")==2)
              {
              $ins_journalad_ad->registerTrigger("END", "Trigger_Default_Redirect", 99, "thankyou.php?id_ad={id_ad}");
              }

              // Redirect to Google Checkout -> payment_card.php
              else if($tNG->getColumnValue("paymethod")==1)
              {
              $ins_journalad_ad->registerTrigger("END", "Trigger_Default_Redirect", 99, "payment_card.php?id_ad={id_ad}&PHPSESSID=".session_id());
              }

              However, that´s experimental, as the transaction values are usually available with Custom Triggers, that is, within PHP functions, and I don´t know how they "behave" outside this realm.

              Please let us know how this works, and if it doesn´t, I´m suggesting to rather create a separate "Redirect to Page" Trigger instance and later define your if/else logic in here, because this one is embedded within a PHP function, means that ADDT´s transaction values are supposed to work in this context.

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver
              • 4. Re: redirect option based on user selection
                Level 1
                Hi Günter

                I tried entering the code. Since my goal is to be able to use the send mail trigger and have the option of redirect, the new code still makes ADDT think that there is no insert trigger, and therefore won't allow a send email trigger.
                • 5. Re: redirect option based on user selection
                  Günter Schenk Level 4
                  Hi Jeremy,

                  did you also try with my alternate solution to create a separate "Redirect to Page" Trigger instance ? This will add such a function:

                  //start Trigger_Redirect trigger
                  //remove this line if you want to edit the code by hand
                  function Trigger_Redirect(&$tNG) {
                  $redObj = new tNG_Redirect($tNG);
                  $redObj->setURL("whatever.php");
                  $redObj->setKeepURLParams(true);
                  return $redObj->Execute();
                  }
                  //end Trigger_Redirect trigger

                  ...and I *think* that in here it should be possible to apply the if-else logic to the $redObj->setURL line this way:

                  --------------
                  if($tNG->getColumnValue("paymethod")==2)
                  {
                  $redObj->setURL("thankyou.php?id_ad={id_ad}");
                  }

                  // Redirect to Google Checkout -> payment_card.php
                  else if($tNG->getColumnValue("paymethod")==1)
                  {
                  $redObj->setURL("payment_card.php?id_ad={id_ad}&PHPSESSID=".session_id());
                  }
                  -------------

                  Cheers,
                  Günter Schenk
                  Adobe Community Expert, Dreamweaver
                  • 6. Re: redirect option based on user selection
                    Günter Schenk Level 4
                    Hi Jeremy,

                    ------
                    the new code still makes ADDT think that there is no insert trigger, and therefore won't allow a send email trigger
                    ------

                    forgot to mention that any of such code manipulation (excluding those which are within Custom Triggers, as they are treated as independant "units") will have this effect -- Dreamweaver/ADDT will always treat the changed code as "non existing trigger", what doesn´t mean that it doesn´t work in the browser.

                    That said, it´s recommended to first apply all triggers to your page and then apply your changes as sort of "last step".

                    Cheers,
                    Günter Schenk
                    Adobe Community Expert, Dreamweaver
                    • 7. Re: redirect option based on user selection
                      Level 1
                      Hi Günter

                      I understand that any editing to the ADDT "normal" triggers will cause it to be non-existing. So I changed the page to have a normal insert trigger, added the send email trigger, and now I'm a little lost. Should I use the code you provided to replace the ADDT insert trigger? And use the if statement in the new trigger? I tried adding it it, and then the normal insert trigger is no longer read by ADDT. Also, it seems the page is broken.
                      • 8. Re: redirect option based on user selection
                        Günter Schenk Level 4
                        Hi Jeremy,

                        just gave my lastmentioned suggestion a try myself, and it does work without errors plus grabs the $tNG->getColumnValue("paymethod") values the way I thought it would.

                        ----
                        Should I use the code you provided to replace the ADDT insert trigger?
                        ----

                        not at all, the existing Insert Transaction will have to remain there, and you don´t need to modify this one.

                        -----
                        And use the if statement in the new trigger?
                        -----

                        use that in the newly created CustomTrigger(Trigger_Redirect) which you should see in the Server Behaviours panel. Whatever you define in this Custom Trigger (including the if/else stuff), will actually override whatever has been defined for the Insert Transaction´s "Trigger_Default_Redirect", so you wouldn´t need to change that.

                        -----
                        I tried adding it it, and then the normal insert trigger is no longer read by ADDT.
                        -----

                        did you maybe modify the Insert Transaction ? That´s not required

                        -----
                        Also, it seems the page is broken
                        -----

                        this is most probably also related to having modified the Insert Trigger, in case you did.

                        Could you post the code of this page on your remote server as .txt file and provide a link ?

                        Cheers,
                        Günter Schenk
                        Adobe Community Expert, Dreamweaver
                        • 9. Re: redirect option based on user selection
                          Level 1
                          Hi Günter
                          Again, many thanks for all the help. I'm still having some issues. I copied the code for the new trigger (kept the default trigger in tact) but was not able to see the custom trigger in the Server Behavior panel. Should I not copy it but use the custom trigger behavior to create it? As you can probably tell - I'm a bit of a novice with this. I removed the new code, and uploaded the file. Here is the link to the txt file:
                          http://www.rjcdinner.org/journalad2.txt
                          Thanks again.

                          Jeremy
                          • 10. Re: redirect option based on user selection
                            Günter Schenk Level 4
                            Hi Jeremy,

                            ------
                            but was not able to see the custom trigger in the Server Behavior panel
                            ------

                            you need to remove the line:
                            //remove this line if you want to edit the code by hand

                            ...from the modified "Redirect to Page" Trigger, DW will then display it in the Server Behavious tab.

                            ----
                            Should I not copy it but use the custom trigger behavior to create it?
                            ----

                            No, please insert a "Redirect to Page" Trigger, have it point to some bogus page, and then apply the if/else condition as described in the previous post. It´s maybe a little tricky to do, but from my testing I can assure it works.

                            -----
                            As you can probably tell - I'm a bit of a novice with this
                            -----

                            We´re all novices in this or that field -- I´ll never tell you how bad I´m with e.g. Flash :-)

                            Cheers,
                            Günter Schenk
                            Adobe Community Expert, Dreamweaver
                            • 11. Re: redirect option based on user selection
                              Level 1
                              Hi Günter

                              Think I'm actually getting somewhere...
                              The only issues left (I hope) are:

                              1. I added the new trigger - just not sure where exactly in the code the if conditional statements go... tried entering it custom trigger behavior clicking on advanced, advanced condition builder, and added the ins_journal_ad transaction, but it produced an error.

                              2. Also, I added my send email trigger - it includes the fields in the form, but when the email is sent, there are no line breaks.

                              At the risk of sounding like a stuck record, thanks again for all the help on this.

                              Jeremy
                              • 12. Re: redirect option based on user selection
                                Günter Schenk Level 4
                                Hi Jeremy,

                                -----
                                1. I added the new trigger - just not sure where exactly in the code the if conditional statements go... tried entering it custom trigger behavior clicking on advanced, advanced condition builder
                                -----

                                Are we still talking about the "Redirect to Page" Trigger respectively the manual if/else modification you would have to apply to this one after it has been generated by ADDT ? Did you insert this type of trigger, or did you insert a standard Custom Trigger ?

                                However, the Trigger´s Condition Builder will be of no use in this case -- you will have to switch to Code View and apply the suggested if/else modification manually.

                                -----
                                and added the ins_journal_ad transaction, but it produced an error
                                -----

                                what error is getting returned precisely ?

                                -----
                                2. Also, I added my send email trigger - it includes the fields in the form, but when the email is sent, there are no line breaks
                                -----

                                are you sending the email as text or as HTML ? AFAIK, sending as text will retain linebreaks. However, if you want to have full control over the email´s formatting, you should give the send email behaviour´s option "Body: Retrieve content from file" a try, as this lets you define an external "template" HTML file.

                                -----
                                At the risk of sounding like a stuck record, thanks again for all the help on this
                                -----

                                My pleasure :-)

                                Cheers,
                                Günter Schenk
                                Adobe Community Expert, Dreamweaver
                                • 13. Re: redirect option based on user selection
                                  Level 1
                                  Hi Günter

                                  I played around with it and realized that the condition builder was not it. So, I added it manually, and it does work! Of course, a new problem has come up - the correct data is not getting passed to the google cart.

                                  There is a session id, etc. and it worked in the original version (before I entered this realm of send email trigger...)

                                  (The original file was edited by some php experts and the reason why I'm trying this on my own is just an issue of time.)

                                  As far as the email - good idea. I'll try the file to solve that problem.

                                  I've posted the 2 files (original journalal.txt and the one we're working on journaladtest2.txt)

                                  Thanks,
                                  Jeremy
                                  • 14. Re: redirect option based on user selection
                                    Günter Schenk Level 4
                                    Hi Jeremy,

                                    ------
                                    I played around with it and realized that the condition builder was not it. So, I added it manually, and it does work!
                                    ------

                                    Congrats !!

                                    -------
                                    There is a session id, etc. and it worked in the original version (before I entered this realm of send email trigger...)
                                    -------

                                    unlike before, you´re now referencing the session_id value within a PHP function, and it seems that this function can´t "see" it right now. Please try with adding...

                                    global $session_id;

                                    ... to the very start of the function and see if it´s now detected correctly.

                                    Cheers,
                                    Günter Schenk
                                    Adobe Community Expert, Dreamweaver
                                    • 15. Re: redirect option based on user selection
                                      Level 1
                                      Hi Günter

                                      I added the line so the trigger reads as follows:

                                      //start Trigger_Redirect trigger
                                      function Trigger_Redirect(&$tNG) {
                                      global $session_id;
                                      $redObj = new tNG_Redirect($tNG);
                                      $redObj->setURL("whatever.php");
                                      if($tNG->getColumnValue("paymethod")==2)
                                      {
                                      $redObj->setURL("thankyou.php?id_ad={id_ad}");
                                      }
                                      // Redirect to Google Checkout -> payment_card.php
                                      else if($tNG->getColumnValue("paymethod")==1)
                                      {
                                      $redObj->setURL("payment_card.php?id_ad={id_ad}&PHPSESSID=".session_id());
                                      }
                                      $redObj->setKeepURLParams(true);
                                      return $redObj->Execute();
                                      }
                                      //end Trigger_Redirect trigger

                                      Unfortunately, had the same problem...

                                      Jeremy
                                      • 16. Re: redirect option based on user selection
                                        Level 1
                                        Jeremy,

                                        Just a couple of quick things.

                                        Are you calling a function called session_id?

                                        $session_id does not equate to session_id()

                                        Unless I am missing something...

                                        $redObj->setURL("payment_card.php?id_ad={id_ad}&PHPSESSID=".session_id());

                                        Should be...

                                        $redObj->setURL("payment_card.php?id_ad={id_ad}&PHPSESSID=".$session_id);

                                        Replacing session_id() with $session_id

                                        $session_id is a variable while session_id() would be a function call to a function named session_id

                                        Also, for security reasons I would not recommend using PHPSESSID in the URL nor passing PHPSESSID thru the url if possible, as this can be a potential security risk. There is not really any reason to pass this via url(GET), especially on a page titled payment_card.php.

                                        Not sure if this would be an issue for your particular page, but it does leave you open to something called session hijacking.

                                        http://en.wikipedia.org/wiki/Session_hijacking

                                        Shane
                                        • 17. Re: redirect option based on user selection
                                          Level 1
                                          Thanks to Günter and Shane for all the help. Due to deadlines, we had some programmers work on this project. They fixed the page (new redirect, emails sent, goes to google correctly, etc.) But the file is no longer editable using ADDT behaviors for novices like myself. I did follow the advice here and was able to get a page that worked (and still was able to be edited using ADDT behaviors) with one problem: the session id was not successfully passed from the form page to a page which collected the data and then sent it on to google (leading to no data in the google cart). For future projects (and my own curiosity) I would love to figure this out. Any help/advice on how to proceed is greatly appreciated.

                                          Jeremy