We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38669
    • 51 Posts
    I know this is stepping into dangerous territory but a client has requested that visitors be able to upload menus to a modx site.

    Obviously any content would need to be not-published to start with and plenty of other content checks. In fact the upload form would be outside of modx and just insert a record into the database.

    So here are some questions peeps may have ideas about (I can already hear BobRay typing smiley )

    • Does something like this already exist?
    • Assuming it doesn't. where in the database is the resource tree info stored. Can't spot it. Doesn't seem to be in each record in site_content so I assume there is a lookup table
    • What are the dependent tables for an item in site_content i.e. apart from the site_content table, what other tables need info inserted to create a resource?

    I would prefer an existing solution of course, but Figuring I am going to have to create this, I am just checking out any traps for the unwary.

    Thanks in advance and I will post my solution here to save others re-inventing the code.
      • 4172
      • 5,888 Posts
      search for formit2Resource for creating resources from frontend

      or formit2db for creating items in custom-tables from frontend

      try moving your mouse over my avatar!
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3749
        • 24,544 Posts
        The site_content table is it. Once a resource is in there, it's in the tree (after things are refreshed).

        Creating a new resource in Revolution is as simple s this:

        $res = $modx->newObject('modResource', array(
            'pagetitle' => 'MyPage',
            'alias' => 'my-page',
            'published' => '0',
         ));
        $res->save();



        So you could do it with a simple form and a snippet (or as Bruno17 suggests, formit2db) or a custom posthook for FormIt.

        If I did that (and I'm not sure I would, even if the client wanted it), I would probably use NewsPublisher, which AFAIK is fairly secure with respect to embedded MODX tags.

        Any time you have user input going directly to the DB and don't require a login, you're on pretty dangerous ground.


        ------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using.
        MODX info for everyone: http://bobsguides.com/modx.html
          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
          • 38669
          • 51 Posts
          Thanks Bruno & Bob,

          Bob I am trying NewsPublisher but get "Sorry . . . There were one or more problems in producing the form: You do not have permission to create a document"

          Was reading the guide but it is a bit confusing regarding ACLs (which I assume is the problem), could you clarify a bit?

          Thanks in advance
            • 3749
            • 24,544 Posts
            In order to use NewsPublisher, you need to log in in the front end as a user with create_document permission. It used to work when previewing from the Manager, but I don't think that works in recent versions of MODX.

            You may also need to have this in the Login tag:

            &contexts=`mgr,web`


            Though I think that's only necessary if you want to use the image or file browser in NP.


            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            MODX info for everyone: http://bobsguides.com/modx.html
              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