21 Replies Latest reply on Dec 20, 2008 2:02 PM by Günter Schenk

    Problem with Multi Page Form (getPrimaryKeyValue() error)

      I'm trying to create a multi page form for the first time. It's a 4 page form and I have it all set up based on the forum thread: multi page form id - sessions? cookies? url? (http://www.adobeforums.com/webx?128@@.59b4c12b) and the form goes thru pretty well, until I click on the Next button to go to page 4 and then I get the following error:

      Fatal error: Call to a member function getPrimaryKeyValue() on a non-object in /home/content/h/u/l/password/html/membership4.php on line 128

      NOTE: password is where the client's password is. For security reasons, I'm using the word 'password' there to represent the actual password.

      So I go to line 128 and I see this code:
      $_SESSION['insertKey'] = $tNG->getPrimaryKeyValue();

      Which is part of this custom function:
      //start Trigger_Custom1 trigger
      $_SESSION['insertKey'] = $tNG->getPrimaryKeyValue();

      function Trigger_Custom1(&$tNG) {
      session_start();

      $_SESSION['form1']['insertKey'] = $tNG->getPrimaryKeyValue();

      }
      //end Trigger_Custom1 trigger

      Which I got from the forum post. So if it's right, where am I wrong? Here's the link to the PHP code:

      http://www.selectiveandsingle.com/membership4.txt

      It's pretty long since it's got a lot of variables it's storing from the previous three webpages.
        • 1. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
          Günter Schenk Level 4
          Hi Adam,

          I´d first try with moving session_start(); outside the "Trigger_Custom" - function and place it at the very beginning of the page -- because a custom trigger incl. all what´s in it gets executed at a later time, whereas a session needs to be initialized on page load

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
            Level 1
            I tried that but all I got was:

            Fatal error: Call to a member function getPrimaryKeyValue() on a non-object in /home/content/h/u/l/hulastyle/html/membership4.php on line 129

            So maybe I didn't understand it. I moved session start up to line 1 like so:



            Now the Custom Trigger looks like this:

            //start Trigger_Custom1 trigger
            $_SESSION['insertKey'] = $tNG->getPrimaryKeyValue();

            function Trigger_Custom1(&$tNG) {

            $_SESSION['form1']['insertKey'] = $tNG->getPrimaryKeyValue();

            }
            //end Trigger_Custom1 trigger

            Was that right or wrong to do?
            • 3. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
              Günter Schenk Level 4
              the $_SESSION['insertKey'] = $tNG->getPrimaryKeyValue(); - syntax appears to be correct, however the "...on a non-object..." error message usually indicates that your "object" (the Session variable) is not correctly set and hence remains a null reference.

              Please try to "echo" this Session variable in the body of your page and see if it returns something or not.

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver
              • 4. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                Level 1
                How do I echo? I don't know how to do that. And as for the session variable, you mean the 'form1' which is where the previous 3 forms were used to create/hold the data. You think I should upload the .txt versions of those pages as well? Maybe I did something wrong there.
                • 5. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                  Günter Schenk Level 4
                  ------ <br />How do I echo? I don't know how to do that <br />------ <br /> <br />please copy/paste the following snippet in your document´s body: <br /> <br /><?php<br />if (isset($_SESSION['insertKey'])) {<br />echo "the session variable insertKey is set";<br />}<br />else {<br />echo "the session variable insertKey is not set";<br />}<br />?> <br /> <br />Cheers, <br />Günter Schenk <br />Adobe Community Expert, Dreamweaver
                  • 7. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                    Günter Schenk Level 4
                    -------
                    Anywhere in the body?
                    -------

                    we need this for debugging purposes, so it doesn´t matter where exactly you put it in the body

                    Cheers,
                    Günter Schenk
                    Adobe Community Expert, Dreamweaver
                    • 8. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                      Level 1
                      OK, I added it but I'm just getting the same message as I did previously.
                      • 9. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                        Günter Schenk Level 4
                        can you temporarily deactivate the Trigger "Custom1" respectively delete the code it contains ?

                        Another option would be to simply "comment" the current code in order to get this error (plus the related message) out of your way, means:

                        function Trigger_Custom1(&$tNG) {
                        /*
                        session_start();

                        $_SESSION['form1']['insertKey'] = $tNG->getPrimaryKeyValue();
                        */

                        }

                        Cheers,
                        Günter Schenk
                        Adobe Community Expert, Dreamweaver
                        • 10. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                          Level 1
                          OK, that worked. Got to Page 4 and filled out the form with a lot of lorem ipsum text since it's a long form. So I clicked on Insert Record to finish the job and then got this error:

                          You can only add supplemental columns by value or by expression once the transaction is started.
                          • 11. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                            Level 1
                            I should also mention at the top of Page 4, I get this message at the top of the form:

                            the session variable insertKey is not set
                            • 12. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                              Günter Schenk Level 4
                              now that the page code must have changed quite a bit since your 1st post, it would be helpful to see an updated version of membership4.txt

                              Cheers,
                              Günter Schenk
                              Adobe Community Expert, Dreamweaver
                              • 13. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                                Level 1
                                I just upped a new version of that file. In addition, I also went ahead and added 3 other files so you can see the entire form in action. just change membership4.txt to membership.txt or membership2 or membership3.
                                • 14. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                                  Günter Schenk Level 4
                                  Thanks for letting me have a look at the different files.

                                  Besides the obvious (moving "session_start" outside your custom trigger and at the very start of the file, like you now did in membership4.txt -- and deleting "session_start" from those functions, as this doesn´t make any sense in this context) I wonder about what you intend to achieve with registering session variables this way (in all files except "membership4.txt"):

                                  $_SESSION['form']['members_pic3'] = $tNG->getColumnValue("members_pic3");

                                  I assume you want to register new session variables (for using them respectively their assigned values on subsequent pages) and assign transaction values to them, correct ? In this case (and with PHP 4.0.6 and later) registering a new session variable is pretty straightforward, example:

                                  $_SESSION['whatever_name'] = $tNG->getColumnValue("members_pic3");

                                  Cheers,
                                  Günter Schenk
                                  Adobe Community Expert, Dreamweaver
                                  • 15. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                                    Level 1
                                    I don't know, Gunther. I just followed the instructions Shane Mosier did in his explanation of how to do a multi-page form and followed his instructions. So look at his post (I linked to it at the top of this thread) and see what he wrote. I guess it's wrong. So if you got a better example on how to properly do it, I'm all ears.

                                    Basically, what I want to do is allow the user to fill out the form in steps and when he/she reached the end and clicks Submit all the data from all four pages gets sent to the DB.

                                    So according to what you suggest, I should move up the session_start to the top of all four pages and then when defining my variables I should not use the name of the form in the listing. Correct?
                                    • 16. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                                      Günter Schenk Level 4
                                      -----
                                      So according to what you suggest, I should move up the session_start to the top of all four pages
                                      -----

                                      yes, Shane says the same in one of his replies: "you can put session_start(); at the top of your PHP page instead of here in the trigger".

                                      ------
                                      and then when defining my variables I should not use the name of the form in the listing
                                      ------

                                      Shane suggests the "$_SESSION['form']['members_pic3']" - type of notation in order to build an array which later (on the very last page) can be destroyed in one swoop using the unset($_SESSION['form']); - command. That´s one way of doing it, the other way is registering session variables using the probably easier to understand $_SESSION['whatever_name'] - notation.

                                      BTW, you wouldn´t have to use the form´s name at all, as the naming is arbitrary -- if you want to build an array of Session variables like Shane suggests, the only important thing to consider is using the same identifier (e.g. "whatever") for all array elements, e.g.

                                      $_SESSION['whatever']['members_pic3'];
                                      $_SESSION['whatever']['members_pic2'];

                                      Now let´s assume you´re passing these session variables (regardless the "naming convention" method) to the next page -- how are your reusing them there, can you post a .txt file of the second form which tries to utilize these variables ?

                                      Cheers,
                                      Günter Schenk
                                      Adobe Community Expert, Dreamweaver
                                      • 17. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                                        Günter Schenk Level 4
                                        Oops, I should have said "please show the code of membership5.php which apparently tries to insert the values of all previously defined session variables into the DB" ;-)

                                        Cheers,
                                        Günter Schenk
                                        Adobe Community Expert, Dreamweaver
                                        • 18. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                                          Level 1
                                          http://www.selectiveandsingle.com/membership5.txt

                                          I'm not sure I did this one right at all. Shane's instructions got a little muddy at this point. This would be a great tutorial to do one of these days at the Dreamweaver Developer Center, you know?

                                          I also updated all the other .txt pages as well so you might want to look at those again. Thanks.
                                          • 19. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                                            Günter Schenk Level 4
                                            What I don´t quite understand, is whether it´s really required to pass the form values via Session Variables at all -- you could also...

                                            1. insert the form values of the first page "membership.php" into the DB...

                                            2. pass the newly inserted record´s Primary Key to the following pages (as URL variable or single Session Variable), which in turn...

                                            3. can contain Update Record behaviours in order to update the very same record, only with other fields of course

                                            Cheers,
                                            Günter Schenk
                                            Adobe Community Expert, Dreamweaver
                                            • 20. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                                              Level 1
                                              Well, I was originally thinking of that myself. Using the first form to post variables to the DB and then each additional form adding more variables to the same table row but different, previously unfilled, variables. My only question to that is how do you pass a URL variable to the next page upon clicking the Insert Record button? Would that involve a different custom trigger?
                                              • 21. Re: Problem with Multi Page Form (getPrimaryKeyValue() error)
                                                Günter Schenk Level 4
                                                -----
                                                My only question to that is how do you pass a URL variable to the next page upon clicking the Insert Record button? Would that involve a different custom trigger?
                                                -----

                                                not at all:

                                                1. doubleclick the "Insert Record Transaction" in the Server Behaviours panel

                                                2. you should see the name of the 2nd form page in the field "after inserting, go to:" -- append "?primary_key=" (without the quotes) to the file name

                                                3. there´s a blue thunderbolt icon to the right of the "Browse..." button -- click this one and select...

                                                a) Get values from: Transaction field

                                                b) Transaction field: choose the column which represents the table´s primary key

                                                c) the corresponding mark-up code displayed in the field below shopuld now display something like {your_primary_key_column_here}

                                                d) confirm with OK to return to the "Insert Record Transaction" window which should now display something like...

                                                form2.php?primary_key={your_primary_key_column_here}

                                                ...in the "after inserting, go to" field.

                                                That´s actually all you´d need to do -- on the subsequent form page you could define an Update Record transaction and make sure that the "Primary key equals:" the URL parameter "primary_key"

                                                Easy as this is, it´s also the most insecure way, because an URL variable and its value will be displayed in the browser´s address bar and can be easily changed by the visitor -- a better way would be to turn the Primary Key into a Session Variable on page 1, but at this point I think you rather deserve a straightforward working solution after all that "register multiple session variables" hullabaloo :-)

                                                Cheers,
                                                Günter Schenk
                                                Adobe Community Expert, Dreamweaver