We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36533
    • 65 Posts
    nuwebstudios Reply #1, 15 years ago
    So, I have a plugin that auto-generates pages on WebSignup working. However, if the user signing up uses any uppercase characters in their username, I can't access the URL when Friendly-URLs are on. It forwards me off to the 404 page. If they are entered in all lowercases, it works fine.

    Here is my plugin:

    <?php
    if($mode=="new"){   
        $wuid = $username;
        $table_name = $modx->getFullTableName( 'site_content' );
        $fields = array(
                            'type'  =>  'document',
                'contentType'   => 'text/html',
                'pagetitle' => $wuid,
                'alias'     => $wuid,
                'published' => '1', //is the page published?
                'parent'    => '16', //what is the parent of this new page?
                'isfolder'  => '0', // lets make this a folder
                'template'  => '15', //type template id here
                'cacheable' => '0',
                'createdby' => $wuid,
                'createdon' => time(),
                'editedon'  => time(),
                'publishedon'   => time(),
                'hidemenu'  => '1'
                );
    
        $modx->db->insert( $fields, $table_name); // put the fields in the db (id wil be created incremental.)
     
    //Create  placeholder and put the id in a session to use for mail or whatever.
    $_SESSION['eigenpaginaid'] =  $modx->db->getInsertId();
    $modx->setPlaceholder('eigenpaginaid', $modx->db->getInsertId());
     
       return;
    }


    Any ideas?
      • 4041
      • 788 Posts
      try this:

      'pagetitle' => strtolower($wuid),
      'alias'     => strtolower($wuid)


      http://www.php.net/manual/en/function.strtolower.php
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 36533
        • 65 Posts
        nuwebstudios Reply #3, 15 years ago
        After testing this a bit more. The page that is generated isn't accessible at all, regardless if the username is lowercase or not.

        If I select preview from the manager immediately after it is generated, I get 35.php instead of, dusman.php (these being my example I'm working with). However, once I edit and save (no changes) it pops right in. If I preview again, after doing edit/save, then it shows dusman.php.

        Accessing the URL directly doesn't work either, until I edit/save.

        It seems to me I might be missing a system event in my plugin? The only one I have selected is OnWebSaveUser. [ed. note: nuwebstudios last edited this post 15 years ago.]
          • 36533
          • 65 Posts
          nuwebstudios Reply #4, 15 years ago
          Can anyone help with this?
            • 3749
            • 24,544 Posts
            I'm not sure how Evo handles this, but in Revo, I think new pages created directly in the DB aren't in the document map yet so they're not accessible to requests. Editing them and saving them would put them there.

            Have you tried accessing them from another browser? A new session might refresh the document map.

            Another solution might be to set the ID in a $_SESSION variable and forward the user to another page containing a snippet that reads that session variable and forwards the user on to the page with $modx->makeUrl() and $modx->sendRedirect().

            Clearing the cache at the end of your snippet might solve the problem, but I can't remember how to do that in Evo and I might be completely off base on the whole thing.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 36533
              • 65 Posts
              nuwebstudios Reply #6, 15 years ago
              I've narrowed this down to friendly URLs not working properly until after the edit/save routine being done. I can access the file through non-friendly url index.php?id=35. Is there any additional PHP I could add in my plugin or a system event I could fire that would engage friendly urls? [ed. note: nuwebstudios last edited this post 15 years ago.]
                • 36533
                • 65 Posts
                nuwebstudios Reply #7, 15 years ago
                BobRay, I think you are on the right track. It doesn't matter how I access the page, it simply isn't available until after I've edited/saved the document.

                I also noticed that the System Event OnBeforeDocSave that it states "$id - Unique ID of the document. Note: this is empty if new document"

                Should I perhaps be firing this system event with some additional code in my plugin?
                  • 36533
                  • 65 Posts
                  nuwebstudios Reply #8, 15 years ago
                  Another update.. which leads me to think you are on the right track BobRay. I created multiple pages this time, which as expected aren't accessible. When I edit/save one.. both become accessible.
                    • 3749
                    • 24,544 Posts
                    I don't think firing other System Events will help you. They don't really do anything but provide hooks for plugins.
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 36533
                      • 65 Posts
                      Any ideas to some alternatives I could look at?