On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
    • Haven't looked at the other thread but a simple create resource from a snippet hook can be as follows:

      <?php
      
      // Create a new resource
      $newResource = $modx->newObject('modDocument');
      
      // Set resources properties
      $newResource->set('pagetitle', 'New Resource');
      $newResource->set('published', '1');
      $newResource->set('template', '1');
      
      $newResource->save();
      
      return true;

      [ed. note: lkfranklin last edited this post 10 months, 1 week ago.]
        ■ email: lk@alienbuild.uk | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
      • There are a few advantages of NewsPublisher over doing it yourself with simple code:

        1. Security -- NP does some serious sanitizing of all user input before writing anything to the DB

        2. NP calls the Resource/Create processor, so any plugins will fire (e.g. defaultResourceGroup)

        3. Easier to configure and change which fields show up in the form

        4. Easier integration of TVs

        5. Built-in Editing solution with EditThisButton.
          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
        • Use custom FORMIT hook like this:

          <?php
          
          // Accessing the FormIt field (in example "name") in the hook
          
          $name = $hook->getValue('name');
          
          // Create resource with runProcessor
          
          $prop = array(
          	'pagetitle' => $name,
          	'parent' => 1,
          	'template' => 1,
          	'isfolder' => 0,
          	'deleted' => 0,
          	'published' => 1
          );
          $response = $modx->runProcessor('resource/create', $prop);
          
          if ($response->isError()) {
          	return $modx->error->failure($response->getMessage());
          }
          
          return;