We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50920
    • 6 Posts
      • 17301
      • 932 Posts
      Haven't looked at the other thread but a simple create resource from a snippet hook can be as follows:

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

      [ed. note: lkfranklin last edited this post 5 years, 8 months ago.]
        ■ email: [email protected] | ■ 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.
        • 3749
        • 24,544 Posts
        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
          • 54199
          • 108 Posts
          Use custom FORMIT hook like this:

          // 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());