9 Replies Latest reply on Feb 6, 2008 12:24 PM by (shane_mosier)

    Pass data from form to confirmation page

      For some reason I can't get this to work and was hoping someone could tell me what I am doing wrong. I remember I had this working correctly at one point and am not sure what broke the function.

      I Created a custom form using the Custom Form Wizard and named the file submit.php. Next I wanted to pass that data to the confirmation page and send an email. The email side works fine however the data from the form never gets passed to the confirmation page.

      Note all files are in the same folder

      Here is my code for the submit.php file

      <?php
      // Load the common classes
      require_once('../includes/common/KT_common.php');

      // Load the tNG classes
      require_once('../includes/tng/tNG.inc.php');

      // Make a transaction dispatcher instance
      $tNGs = new tNG_dispatcher("../");

      // Make unified connection variable
      $conn_chemcompany = new KT_connection($chemcompany, $database_chemcompany);

      // Start trigger
      $formValidation = new tNG_FormValidation();
      $tNGs->prepareValidation($formValidation);
      // End trigger

      // Make a custom transaction instance
      $customTransaction = new tNG_custom($conn_chemcompany);
      $tNGs->addTransaction($customTransaction);
      // Register triggers
      $customTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Custom1");
      $customTransaction->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
      $customTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "receive.php");
      // Add columns
      $customTransaction->addColumn("name", "STRING_TYPE", "POST", "name");
      // End of custom transaction instance

      // Execute all the registered transactions
      $tNGs->executeTransactions();

      // Get the transaction recordset
      $rscustom = $tNGs->getRecordset("custom");
      $row_rscustom = mysql_fetch_assoc($rscustom);
      $totalRows_rscustom = mysql_num_rows($rscustom);
      ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Untitled Document</title>
      <link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
      <script src="../includes/common/js/base.js" type="text/javascript"></script>
      <script src="../includes/common/js/utility.js" type="text/javascript"></script>
      <script src="../includes/skins/style.js" type="text/javascript"></script>
      <?php echo $tNGs->displayValidationRules();?>
      </head>

      <body>

      <?php
      echo $tNGs->getErrorMsg();
      ?>
      <form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
      <table cellpadding="2" cellspacing="0" class="KT_tngtable">
      <tr>
      <td class="KT_th"><label for="name">Name:</label></td>
      <td><input type="text" name="name" id="name" value="<?php echo KT_escapeAttribute($row_rscustom['name']); ?>" size="32" />
      <?php echo $tNGs->displayFieldHint("name");?> <?php echo $tNGs->displayFieldError("custom", "name"); ?> </td>
      </tr>
      <tr class="KT_buttons">
      <td colspan="2"><input type="submit" name="KT_Custom1" id="KT_Custom1" value="Submit" />
      </td>
      </tr>
      </table>
      </form>
      </body>
      </html>

      and this is the code for the confirmation page

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Untitled Document</title>
      </head>

      <body>
      <?php echo $_POST['name']; ?>
      </body>
      </html>

      Please please let me know what I have wrong?????
        • 1. Re: Pass data from form to confirmation page
          Günter Schenk Level 4
          Hi Chris,

          it should be , because variables appended to a Redirect URL are getting transmitted as URL parameters.

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: Pass data from form to confirmation page
            Level 1
            Günter,

            You know I look at using <?php echo $_GET['name']; ?> however the name value is not getting appended to the url when submitted from the submit.php field.

            Could it be a setting with the server not passing the data??? Now what has me stumped is if I set up send email and map to an html email template in the includes folder the data from the form is inserted into the email and is not being passed to the confirmation.php page?????

            any other suggestions?
            • 3. Re: Pass data from form to confirmation page
              Günter Schenk Level 4
              oops, guess I missed the most important part :: variables and some transaction values need to be appended this way:

              $customTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "receive.php?name={name}");

              Works better now ?

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver
              • 4. Re: Pass data from form to confirmation page
                Level 1
                Günter,

                That worked but can't you pass data from one page to another without appended to the url???
                • 5. Re: Pass data from form to confirmation page
                  Günter Schenk Level 4
                  Hi Chris,

                  -----
                  but can't you pass data from one page to another without appended to the url???
                  -----

                  well, "passing data" means to explicitely define what data is going to be passed, and the available methods are transferring data via URL or form parameters. ADDT´s and Dreamweavers native "Redirect after Insert/Update" method is using the URL variant.

                  Cheers,
                  Günter Schenk
                  Adobe Community Expert, Dreamweaver
                  • 6. Re: Pass data from form to confirmation page
                    Level 1
                    Günter,

                    I was able to pass the data without appending it to the url; just had to change the follow code and it worked... When I built this locally every thing worked but after I uploaded the files to the live site I could no longer pass the data.

                    Took this line of code
                    <form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">

                    and changed it to...

                    <form action="receive.php" method="post" id="form1">

                    So i wonder if the issue is...
                    <?php echo KT_escapeAttribute(KT_getFullUri()); ?>
                    • 7. Re: Pass data from form to confirmation page
                      Günter Schenk Level 4
                      Chris,

                      what´s the problem with passing some data to the Redirect page via URL parameters ?

                      ------

                      ------

                      KT_escapeAttribute(KT_getFullUri()) returns a string with the current page's URL, and this will make sure that the same form (page) is getting reloaded in case an Insert or Update procedure failed for whatever reason, or if the user will have to fill out missing fields -- so defining another page in the form´s "action" might work, but isn´t really a recommendable solution IMO

                      Cheers,
                      Günter Schenk
                      Adobe Community Expert, Dreamweaver
                      • 8. Re: Pass data from form to confirmation page
                        Level 1
                        I guess I didn't want to show via the url that data is being passed. Also since it worked without added to the url in my local build I was trying to find out why I have to add it in the url for the live site. At this point I am trying to find out what is different between local and the live site.

                        Perhaps if I could get some background of the following code does

                        <?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
                        • 9. Re: Pass data from form to confirmation page
                          Level 1
                          Chris,

                          <?php echo KT_escapeAttribute(KT_getFullUri()); ?>">

                          is important because basically ADDT forms work by having the forms submit back to themselves.

                          Günter was explaining that that code returns the current page's URL. In order for all the error checking to work(client side and server side) and for the custom triggers to work, an ADDT form calls back to itself for the form action. This is why you cannot pass variables via POST with ADDT forms. As Günter said, I don't recommend changing the action.

                          The simplest and most straightforward way to pass variables in ADDT forms is thru the URL.

                          Another alternative is to use SESSION variables. This way the user will not see what is being passed. Sometimes it is important to hide this from the user. However, using session variables requires more work and some accounting in your code. Also, you may run into other issues because session variables work best by using cookies on the clients computer. They should work even without cookies enabled, but just be aware.

                          You have to use the following php code:

                          session_start();

                          in your page to be able to call and set session variables.

                          You would need a custom trigger added to the ADDT form that grabs the submitted info from your form and puts it into a session variable.

                          Example:

                          $_SESSION['forminput']['customerName'] = $tNG->getColumnValue("Customer_Name");

                          You would do this for each form element you are trying to pass.

                          I tend to use session array variables rather than session variables:

                          I would use:
                          $_SESSION['forminput']['customerName']

                          Rather than:
                          $_SESSION['customerName']

                          The reason for this is that I can clear all the variables for that array with one line:

                          unset($_SESSION['forminput']);

                          Rather than having to unset each variable. You can also clear all session variables by the following code:

                          session_destroy();

                          Hope this helps,

                          Shane