We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15716
    • 57 Posts
    I’m new to a lot of this stuff, so hopefully this is easy...

    The goal is to have the registered, logged-in user take a survey only ONE time...
    So my plan is to have them take the survey (while logged in) and when they hit the submit button, delete their user profile.
    This way they can not log back in and retake the survey.

    How should I go about doing this (code examples would really help). I’m not sure how to put all of this together, but from what I have seen and done so far it’s an awesome tool.

    Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The SESSION has all of the information you need (specifically the internalKey), so part of processing the vote (after the vote results have been successfully saved) just delete from the web_users, web_users_attributes and webgroups tables where the userid is the SESSION[’internalKey’].
      $modx->db->delete($modx->getFullTableName('web_users'), 'id='.$_SESSION['internalKey']);

      repeat for the other two tables. For the web_user_attributes table use the internalKey field; for the webgroups table use the webuser field.

      Of course, if the user was never assigned to a web group you can skip that one.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 24530
        • 100 Posts
        hi kev!
        Do you really need to delete the users? this way you don´t know who took part of the survay ... you could use a new field "survey". or set the field `modx_web_user_attributes`.`blocked` of the mysql database to 1. this way the userdata doesn´t get lost. the snippet WebLoginPE could help.

        good luck!
          my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
          • 15716
          • 57 Posts
          Thanks for the replies. Everyone’s input is much appreciated.

          Maybe I should go with just disabling the user instead of deleting them. As long as they can not log in anymore...
          Is setting the attributes to "blocked" the easiest way of denying access?

          Any thoughts?
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Yes, just update the table, set blocked = 1 where internalKey = $_SESSION[’internalKey’].
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 15716
              • 57 Posts
              I can’t seem to get ’id=’.$_SESSION[’internalKey’]) to work...if I manually enter in the ID, this works fine.

              But when I try the ’id=’.$_SESSION[’internalKey’]), nothing happens. What am I doing wrong?

              $modx->db->update(’blocked = "1"’, $modx->getFullTableName(’web_user_attributes’), ’id= "8"’);
              vs.
              $modx->db->update(’blocked = "1"’, $modx->getFullTableName(’web_user_attributes’), ’id=’$_SESSION[’internalKey’]));

              Help! Thanks once again.
                • 24530
                • 100 Posts
                please have a look onto the quotes, braces and points!
                they seem a little bit chaotic ...

                maybee this is better (not tested!):
                $modx->db->update(’blocked = "1"’, $modx->getFullTableName(’web_user_attributes’), ’id="’.$_SESSION[’internalKey’].’"’);
                  my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f