We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10355
    • 44 Posts
    Hello please tell me how best to do in Revo.
    I want to ensure web users can create a resourse through forms (metod POST) with TV

    how best to write a snippet?
    I guess that through newObject (’modDocument’); but how?
      • 3749
      • 24,544 Posts
      You could do it as a custom hook in the FormIt snippet or with a snippet.

      Creating a resource in code is as simple as this:


       
      $createdBy=$modx->user->get('id');
      
      $flds = array(
                      'pagetitle'     => $title,
                      'longtitle'     => $longtitle,
                      'description' => $description,
                      'introtext'     => $introtext,
                      'alias'             => $alias,
                      'parent'            => $folder,
                      'createdon'     => $createdon,
                      'createdby'     => $createdBy,
                      'editedon'        => '0',
                      'editedby'        => '0',
                      'published'     => $published,
                      'pub_date'        => $pub_date,
                      'unpub_date'    => $unpub_date,
                      'deleted'         => '0',
                      'hidemenu'        => $hidemenu,
                      'menuindex'     => $mnuidx,
                      'template'        => $template,
                      'content'         => $header.$content.$footer
                  );
                 $resource = $modx->newObject('modResource',$flds);
                 $resource->save();
      


      You can also set individual fields with:

      $resource->set('fieldName',$value);


      BTW, I’m working on a Revolution conversion of the old NewsPublisher snippet, which may do what you want, but I don’t know when it will be available.

        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
        • 22303 MODX Staff
        • 10,725 Posts
        'createdby' => ($userid>0 ? $userid * -1:0)

        mysql_escape_string($header.$content.$footer)

        *blink* huh

        I think that is Evo code you are demonstrating there...
          • 3749
          • 24,544 Posts
          Quote from: OpenGeek at Nov 08, 2010, 04:22 PM

          'createdby' => ($userid>0 ? $userid * -1:0)

          mysql_escape_string($header.$content.$footer)

          *blink* huh

          I think that is Evo code you are demonstrating there...

          Oops. I swiped the code from the unfinished NewsPublisher snippet I’m working on. What should mysql_escape_string() be in Revo?

          BTW, it’s up at https://github.com/BobRay/newspublisher (with those errors ATM).
            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
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: BobRay at Nov 08, 2010, 10:27 PM

            Oops. I swiped the code from the unfinished NewsPublisher snippet I’m working on. What should mysql_escape_string() be in Revo?
            You don’t need to use anything if you are using bound parameters with prepared statements, as save()’ing xPDOObjects does. Prepared statements automatically PDO::quote() the values you bind. If you were to author direct SQL and not use a prepared statement, you could manually call $modx->quote($userInput), but again, this is not necessary in the form you are using here.
              • 4172
              • 5,888 Posts
              you can also try the formit2resource-hook and modify it to your needs
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 10355
                • 44 Posts
                Thanks,

                Dear BobRay well as in your version of the add TV value?