13 Replies Latest reply on Nov 28, 2009 1:13 PM by James_PT

    Ask for more user information before send.

    meezone Level 1

      Hello,

       

      I made a user registration page and a login page (used Dreamweaver Developer Toolbox)

       

      So after the user left his emailadres (it is directly his login) he is redirected to another page.

       

      Now i want this user do get an email after click a button (in a form). But first i need more information from this (already registered user: His Name, Lastname etc) before he is allowed to download the email.

       

      When this user has complete this form (and updated his profile) he is allowed do get the email by click on the button.

       

      When this user is comming back the seccond time he can download emails automaticly. Because he has already updated his profile.

       

      How do i have to make this working?

       

      thnks alot!

        • 1. Re: Ask for more user information before send.
          James_PT Level 1

          There are a couple of ways to do this, some involving Javascript.  Perhaps the easiest way would be to have a column in your user table (the one accessed at login) to contain an authentication group.  Value of Y, already been through the process, value of N (default) means needs to update his profile.  At login attempt, ADDT will check this column and you can direct the user to the Update Your Profile screen if the value is N, then to the home screen; otherwise simply pass him on to the home screen.  Of course, you will need to update the group column with a Y for those initially updating their profile.  You can do this through PHP or through a Custom Trigger (Before Update), or by adding a Transaction Field set to the value of Y.

          • 2. Re: Ask for more user information before send.
            meezone Level 1

            Do you mean with levels?

             

            Is it possible to have an if/else statement on the send email button:

             

            (on click) - If value = Y >>> send email directly.

            (on click - if value = N >>> direct the user to the update field?

             

            Can i built this with ADDT (php)?

             

            Thanks.

            • 3. Re: Ask for more user information before send.
              James_PT Level 1

              You should be able to put a condition statement around the Send button (Show If Conditional).  When you bring up the page, check the value of the column you are using in the recordset.  Keep in mind though, that this is a server behavior so nothing will change dynamically on the screen.  The first time, when the value is N, the button will not display.  Once you update the column to Y, then the button will always display.  If you are more ambitious, you can use a javascript statement (remember to append _01 to the column name as ADDT changes the field names on the screen).  You could enable or disable the send button based upon dynamic input.

               

              I've used both methods around the existing EDIT and DELETE buttons to prevent updating a form if I have "locked" the database.  Show If Conditional avoids javascripting and is pretty straight forward.

               

              J

              • 4. Re: Ask for more user information before send.
                meezone Level 1

                Thanks alot for your help! I am almost there..

                 

                one questions:

                 

                Users can enter the site in 2 ways:

                 

                1) after login (go to index_logged_in.php). So after here i know the value of 'Y' or 'N'

                 

                2) from the index.php (not logged in yet!). So this user is not logged in yet, how do i know if the value is 'Y' or 'N'

                 

                (because in this case both forms are empty. There is either 'Y' nor 'N'

                 

                 

                 

                Thanks again!

                • 5. Re: Ask for more user information before send.
                  James_PT Level 1

                  They will have to give you something on the index.php screen by which you can identify them.  I

                   

                  f they are already logged in, no problem, you've got them under control.  If they are not logged in, I'm not sure you want them doing anything anyway since it is a security issue?

                   

                  You can of course ask for their email address and use it to find out whether they have a completed profile in the database table even if they are not logged in.  Just create another recordset that reads the table using the email address as the key.  Keep in mind though, that anyone can put in someone else's email address.  I'm probably not telling you anything new here.

                  • 6. Re: Ask for more user information before send.
                    meezone Level 1

                    Hi thanks for your reply.

                     

                    (Just create another recordset that reads the table using the email address as the key.)

                     

                    How do you create it in ADDT? I was looking for the query builder, but i can't find it?

                     

                    thanks.

                    • 7. Re: Ask for more user information before send.
                      James_PT Level 1

                      From either the Bindings or Server Behavior panel, click the '+', then select Recordset.  It will lead you through the process.  Just select the table and the columns and you're good to go.  Then select the Filter option and select the name of the email_address field on your screen.  You will need to pass the recordset the email address you are going to use as a key as a URL parameter.  This will retrieve the attribute columns for that email address from your table.

                       

                      All recordsets are executed when the page opens so the values will be in your specified columns in your recordset.

                       

                      J

                      • 8. Re: Ask for more user information before send.
                        meezone Level 1

                        Do you know if on logout i can change for exemple a database table (logged_in_usr) Y / N?

                         

                        thanks.

                        • 9. Re: Ask for more user information before send.
                          James_PT Level 1

                          Sure,  There are any number of ways to do this whether you are using the logout server behavior or just using a link back to the login page.

                           

                          If you are using the ADDT Logout Transaction, you can simply add a custom trigger.  Set it up to fire before the logout transaction executes, then in the trigger code you will need to add the following PHP code that updates the column with the value you want for that user. To create the customer trigger, go to Server Behaviors, +. Developer Toolbox, Forms, Custom Trigger.  The Logout Transaction is listed.  Selected it an set the action to BEFORE.

                           

                          In the trigger code section, you can place:

                           

                          $sql = "UPDATE user_table SET status_column = 'Y' WHERE user_table.userid  = " . $_SESSION['kt_login_id'];

                          //kt_login_id is automatically established by ADDT upon a user's successful login, concatenate this to the SQL literal

                           

                          //execute the sql statement and check for success

                          $result = $tNG->connection->execute($sql);

                          if (!$result) {

                             $updateError = new tNG_error("Error retrieving user profile",array(),array());

                              return $updateError;

                          }

                          • 10. Re: Ask for more user information before send.
                            meezone Level 1

                            I get the following error: Error retrieving user profile (Error retrieving user profile)

                             

                            - name of my user table is 'login_user'

                            - name of user id is 'id'

                             

                            - On logout i want to change the colum 'status_usr' from Y to nothing/empty

                             

                            In de custom trigger window i have this code:

                             

                             

                            $sql = "UPDATE login_user SET status_usr = 'N' WHERE login_user.id  = " . $_SESSION['kt_login_id'];

                             

                            //kt_login_id is automatically established by ADDT upon a user's successful login, concatenate this to the SQL literal

                             

                            //execute the sql statement and check for success

                             

                            $result = $tNG->connection->execute($sql);

                             

                            if (!$result) {

                             

                               $updateError = new tNG_error("Error retrieving user profile",array(),array());

                             

                                return $updateError;

                             

                            }

                            • 11. Re: Ask for more user information before send.
                              James_PT Level 1

                              So your SQL statement is executing but it is returning an empty result set. The error message you get is the one you specified to display if the result set is empty.  This is due to one of two problems:  (1), you have an error in your SQL syntax; or (2), you aren't selecting any rows because of an improper key match.

                               

                              If your login_user.id column is the user's login name, then try changing the kt_login_id variable to kt_login_user, it depends how your table is setup.  kt_login_user should contain the username of the person who logged in.  Both are session variables.

                               

                              The best way to debug your SQL is to run it separately in an SQL execute window, part of Xamp or Wamp.  You can also, and should, use an echo statement to display on your screen the actual SQL that is generated.  If you do this and an error is not obvious, copy it and run it outside of your application in the Xamp SQL window and just verify that you get an update success.  An easy way to do this is to simply add the following statements:

                               

                              echo $sql;

                              exit;

                               

                              within the if statement that checks the success of your query:

                               

                              if (!$result) {

                                 echo $sql;

                                 exit;

                                 $updateError = new tNG_error("Error retrieving user profile",array(),array());

                                  return $updateError;

                              }

                               

                              Don't forget to take them out when you're done.

                              • 12. Re: Ask for more user information before send.
                                meezone Level 1

                                i can't get it working.

                                 

                                I tried kt_login_id and kt_login_user.

                                 

                                In the bold syntax ok (from your first post)?

                                 

                                $sql = "UPDATE user_table SET status_column = 'Y' WHERE user_table.userid  = " . $_SESSION['kt_login_id'];

                                //kt_login_id is automatically established by ADDT upon a user's successful login, concatenate this to the SQL literal

                                 

                                //execute the sql statement and check for success

                                $result = $tNG->connection->execute($sql);

                                if (!$result) {

                                   $updateError = new tNG_error("Error retrieving user profile",array(),array());

                                    return $updateError;

                                }

                                 

                                 

                                I replaced this to my settings (my table name = login_user):

                                 

                                - user_table = login_user

                                - status_column = status_usr

                                - user_table.userid = login_user.id why do you have to write login_user.id ??

                                 

                                 

                                so then i get:

                                 

                                $sql = "UPDATE login_user SET status_usr = 'Y' WHERE login_user.id  = " . $_SESSION['kt_login_id'];

                                //kt_login_id is automatically established by ADDT upon a user's successful login, concatenate this to the SQL literal

                                 

                                //execute the sql statement and check for success

                                $result = $tNG->connection->execute($sql);

                                if (!$result) {

                                   $updateError = new tNG_error("Error retrieving user profile",array(),array());

                                    return $updateError;

                                }

                                 

                                If i hover over the logout button i see this:

                                 

                                index_ingelogd.php?KT_logout_now=1

                                 

                                 


                                In my registrationpage i have this cutom trigger (to automaticly login)

                                 

                                $_SESSION['kt_login_id'] = $tNG->getPrimaryKeyValue();
                                KT_setSessionVar('kt_login_id');
                                $_SESSION['kt_login_user'] = $tNG->getColumnValue('email_usr');
                                KT_setSessionVar('kt_login_user');

                                 

                                 

                                Thank alot for all your help!!

                                 

                                Message was edited by: meezone

                                • 13. Re: Ask for more user information before send.
                                  James_PT Level 1

                                  Did you get the error message?

                                   

                                  Did you display the SQL on the screen with the echo statement?

                                   

                                  Can you copy and post the result of your SQL statement in this post?

                                   

                                  Can you run the generated SQL syntax in phpadmin without error?

                                   

                                  What is the value in the primary key you are trying to use?  Does the value of the session variable equal the value of the column in the table?

                                   

                                  If you display the SQL, you should be able to see the problem.

                                   

                                  You don't necessarily have to preface the id with the name of the table, login_user.id explicitly references the column name id in your login_user table.  Preferencing with the table name removes any ambiguity (id could be construed as a reserve word by itself).

                                   

                                  Remember, the only time this will trigger is when someone clicks logout, if they simply close their browser, it won't work.

                                   

                                  Also, looks like you are maniuplating the value of kt_login_id, are you sure you are setting it to the right value?  It looks like you have a primary key, a userid, and a password column in your login table?  kt_login_id and id must be equal (an integer?)