We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    to get the id, you need to save the resource

    $doc->save();


    then you can get the id with

    $id=$doc->get('id');


    after that and if you want to have the alias is the id you can set your alias with

    $doc->set('alias', $id);


    and save your resource again

    $doc->save();
      -------------------------------

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
      • 16633
      • 116 Posts
      Thank you that worked great.

      But even using http://rtfm.modx.com/display/ADDON/FormIt.Example+1+-+Contact+Page

      Nothing gets populated here: <p>[[+fi.error.error_message]]</p>

      I copied pasted straight from the example.
        --
        Landon Poburan
        Web Designer and Developer

        http://www.categorycode.ca
        http://www.landonp.com
        • 16633
        • 116 Posts
        Quote from: Bruno17 at Oct 25, 2010, 03:45 PM

        to get the id, you need to save the resource

        $doc->save();


        then you can get the id with

        $id=$doc->get('id');


        after that and if you want to have the alias is the id you can set your alias with

        $doc->set('alias', $id);


        and save your resource again

        $doc->save();


        That worked, but then stopped working? It is not saving with a URL it is weird. So when I save it and the go to the page that is displaying them, there is no URL. But when I clear the cache in the manager, then view the page they are displayed on, it works. Here is the formit2resource snippet:


        <?php

        $doc = $modx->getObject(’modResource’,array(’id’=>$hook->getValue(’resource_id’)));

        if (empty($doc)){
        $doc = $modx->newObject(’modResource’);
        $doc->set(’createdby’, $modx->user->get(’id’));
        }
        else{
        $doc->set(’editedby’, $modx->user->get(’id’));
        }

        $allFormFields = $hook->getValues();
        foreach ($allFormFields as $field=>$value)
        {

        if ($field !== ’spam’ && $field !== ’resource_id’){
        $doc->set($field, $value);
        }
        }

        $doc->set(’template’, ’2’); // Use NominationTemplate
        $doc->set(’published’,’1’); // Set resource to be published.
        $doc->save();

        $id=$doc->get(’id’);
        $doc->set(’alias’, $id);
        $doc->save();

        foreach ($allFormFields as $field=>$value)
        {
        if ($tv = $modx->getObject(’modTemplateVar’, array (’name’=>$field)))
        {
        /* handles checkboxes & multiple selects elements */
        if (is_array($value)) {
        $featureInsert = array();
        while (list($featureValue, $featureItem) = each($value)) {
        $featureInsert[count($featureInsert)] = $featureItem;
        }
        $value = implode(’||’,$featureInsert);
        }
        $tv->setValue($doc->get(’id’), $value);
        $tv->save();
        }
        }

        return true;
        ?>
          --
          Landon Poburan
          Web Designer and Developer

          http://www.categorycode.ca
          http://www.landonp.com
          • 4172
          • 5,888 Posts
          you can call your snippet which lists them uncached or set the resource to uncached or clear the cache after saving with something like that:

              /* empty cache */
              $cacheManager= $modx->getCacheManager();
              $cacheManager->clearCache(array (
                      "{$doc->context_key}/resources/",
                      "{$doc->context_key}/context.cache.php",
                  ),
                  array(
                      'objects' => array('modResource', 'modContext', 'modTemplateVarResource'),
                      'publishing' => true
                  )
              );
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 16633
            • 116 Posts
            Quote from: Bruno17 at Oct 26, 2010, 03:15 AM

            you can call your snippet which lists them uncached or set the resource to uncached or clear the cache after saving with something like that:

                /* empty cache */
                $cacheManager= $modx->getCacheManager();
                $cacheManager->clearCache(array (
                        "{$doc->context_key}/resources/",
                        "{$doc->context_key}/context.cache.php",
                    ),
                    array(
                        'objects' => array('modResource', 'modContext', 'modTemplateVarResource'),
                        'publishing' => true
                    )
                );


            I currently am calling getresources uncached so I will try your code snipped to clear the cache once the resource is saved. Should I drop that at the end of the formit2resource snippet before "return true;"
              --
              Landon Poburan
              Web Designer and Developer

              http://www.categorycode.ca
              http://www.landonp.com
              • 4172
              • 5,888 Posts
              Quote from: landonpoburan at Oct 26, 2010, 03:30 PM

              I currently am calling getresources uncached so I will try your code snipped to clear the cache once the resource is saved. Should I drop that at the end of the formit2resource snippet before "return true;"

              exact.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 16633
                • 116 Posts
                Works like a charm! Thanks a million.

                1 Last question! I hope I am not being a pain! Am I able to upload a file to the /assets/ directory using Formit?
                  --
                  Landon Poburan
                  Web Designer and Developer

                  http://www.categorycode.ca
                  http://www.landonp.com