We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7155
    • 160 Posts
    Sorry if this is in the wrong place. Was caught between this forum and the WebloginPE forum. I thought this would be best

    I have a snippet that makes use of certain custom tables. I would like to "capture" some data from the user on registration. This data will then be saved in these custom tables in a particular way. Am I right to think that I need a plugin for this?

    I would like to get fields included in the Weblogin registration template BUT not saved/required by WebloginPE.

    Can I get the events fired by WebLoginPE and save certain data from it.

    I dont know if I’m making any sense, but somehow I think plugins would work

    ...or I could be wrong undecided
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      WebLoginPE can save additional user info in a separate table, and this might provide an easy way for you to populate a custom table with user-supplied data. The WebLoginPE’s profile page can be used to read this data back for users wishing to edit "their" info... but you can of course limit their access to this additional information and handle it via your own Snippet for example.
        • 7155
        • 160 Posts
        Quote from: Everett at Jul 22, 2009, 12:00 PM

        WebLoginPE can save additional user info in a separate table, and this might provide an easy way for you to populate a custom table with user-supplied data. The WebLoginPE’s profile page can be used to read this data back for users wishing to edit "their" info... but you can of course limit their access to this additional information and handle it via your own Snippet for example.
        Thanks, I do understand...but I have a module that adds certain related data and some of that is used on registration or in the user profile.

        I attempted to write a plugin, but unfortunately it shows me a blank screen. I read the API documentation.



        <?php


        $e = &$modx->Event;

        // plugin path
        $pluginPath = $modx->config["base_path"]."assets/plugins/myplugin/";

        // include main class
        include_once $pluginPath."myclass.class.php";

        $mc = new myClass();


        // Event switch
        switch($e->name)
        {

        case "OnWebSaveUser":

        if($mode=="new")
        {

        $mc->SomeAction($user);

        }
        elseif($mode=="update")
        {
        if($_SESSION[’webInternalKey’] > 0)
        {
        $mc->SomeAction($user,$_SESSION[’webInternalKey’]);
        }
        }

        break;



        default:

        return;
        break;
        }
        ?>
          • 7155
          • 160 Posts
          I shouldve used the right term, I need to handle normalised data. I think you had a similar challenge here:

          http://modxcms.com/forums/index.php/topic,34919.msg211780.html#msg211780

          I cant seem to see any other way but the plugin/snippet way. Any hints on what couldve made my page blank out after adding my plugin code? I stripped everything else then "echo"ed some text with an exit; so I see the that it is working under the event, but still nothing.

          I also came across another thread of yours whilst searching (http://modxcms.com/forums/index.php/topic,34924.0.html ). Will read through it once I get time on my hands.
            • 9207 ☆ A M B ☆
            • 2,475 Posts
            Yeah, writing normalized data to multiple database tables is a tricky problem. To be honest, I never did figure out a good way to do this with WebLoginPE... probably just because the documentation was lacking or too confusing for my dense way of thinking. I seriously need full examples of anything for me to understand it the first time around.

            What I ended up doing is writing a CRUD framework that works in MODx... which is way more work than I thought it would be, but that at least lets me write my own MySQL queries (which I’m very comfortable with). It’s easier for me if I can get my hands on exactly what is going in and out of the database.

            However.... for your particular problem, I’d recommend just slogging through the debugging. Keep putting in "print" statements in your plugin code until you can find where it’s breaking and what the values are that are causing it to break. Another tactic is to /* comment out */ large chunks of code so you can narrow down where exactly the thing is dying. Sometimes it’s not where you’d think.

            Hopefully that helps. Good luck!
              • 7155
              • 160 Posts
              Quote from: Everett at Jul 23, 2009, 11:26 AM

              Yeah, writing normalized data to multiple database tables is a tricky problem. To be honest, I never did figure out a good way to do this with WebLoginPE... probably just because the documentation was lacking or too confusing for my dense way of thinking. I seriously need full examples of anything for me to understand it the first time around.

              What I ended up doing is writing a CRUD framework that works in MODx... which is way more work than I thought it would be, but that at least lets me write my own MySQL queries (which I’m very comfortable with). It’s easier for me if I can get my hands on exactly what is going in and out of the database.

              However.... for your particular problem, I’d recommend just slogging through the debugging. Keep putting in "print" statements in your plugin code until you can find where it’s breaking and what the values are that are causing it to break. Another tactic is to /* comment out */ large chunks of code so you can narrow down where exactly the thing is dying. Sometimes it’s not where you’d think.

              Hopefully that helps. Good luck!


              thanks for the tips. For one part of it, I had to modify the actual snippet. I know its not good practise but I had no choice. I’ve been stuck on the plugin for almost a week now. I wish there was an API example to go with the documentation. Its clearer when it’s by example, like you say.
              This is what I did

              I created my snippet for my custom fields, from normalised tables

              I types and services e.g. "register" and "cancel"

              then called my snippet(which generates chunks) within that will be used depending on the WebloginPE call. Its messy and not advisable to do, but I had no choice. I used $modx->runSnippet to run the snippet.

              The most troublesome error I keep encountering is Redefining already defined constructor for class WebLoginPE.

              Hopefully I’ll get there soon

                • 7155
                • 160 Posts
                I ended up having to create a plugin and managed to debug the first troublesome bits.

                Let me share my solution to my problem. I used the same approach for other aspects of the project. So I will give one example which can be duplicated for similar requirements.

                I had my own custom fields which also had a link to a custom module. I had normalised tables which I wanted the custom fields to be taken from. The challenge was having to display the custom fields when webloginpe was called either when:

                1) a user views his/her own profile for editing
                2) another user/website visitor views that users profile

                The major challenge was on 1)

                My Solution:
                I modified WebloginPE code and added my own Event(OnBeforeViewEditProfile) in the code (I cannot see the line number coz I’m on notepad right now...not my PC. You can search for "$system_eventnames =" to find the code section):

                File: webloginpe.class.php
                // Create the additional MODx events if they do not exist
                			$system_eventnames = $modx->getFullTableName('system_eventnames');
                			$newEvents = array('OnBeforeWebSaveUser', 'OnBeforeAddToGroup', 'OnViewUserProfile','OnBeforeViewEditProfile');//designetic: added OnBeforeViewEditProfile
                


                Then before a profile is viewed, I "invoked" the event. I wrote a corresponding WebloginPE function(scroll down in the "webloginpe.class.php" file for examples) which passed on the parameters I needed in my plugin.

                Then I just needed to add &tableCheck to just one place where there is a WebloginPE call:
                &tableCheck=`1`

                This makes it create the Event and execute the code above.

                The Event will then be added to MODx and you can see it in your plugin configurations.

                I ticked this then "listened" to the event in my plugin code.

                My plugin then created a placeholder which would be used in the template.

                And thats it!