We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14050
    • 788 Posts
    getTemplateVarOutput() is not a PHP function. You have to access it through the $modx object, so try this:

    <?php
    $idname = 'event_date';
    echo $modx->getTemplateVarOutput($idname);
    ?>
    
      Jesse R.
      Consider trying something new and extraordinary.
      Illinois Wine

      Have you considered donating to MODx lately?
      Donate now. Every contribution helps.
      • 27708 MODX Staff
      • 2,502 Posts
      Ahh. Right. I did that before and it is so long ago I couldn’t remember.
        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
        • 7231
        • 4,205 Posts
        Doesn’t FDM use eForm? If so could you not use one of the eForm events to run this snippet? I admit that I know nothing about eForm yet and have just played around with FDM, but rather than doing a plugin (which would run regardless of the form) you could use an eForm even and have this be activated directly by the FDM form. Just an idea, not sure if it is any use.
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 27708 MODX Staff
          • 2,502 Posts
          @dev_cw

          I looked at the eForm events but can’t figure out which event one would use.

          Personally I feel that it should be easy to do this but I am stumped. I have tried to call the getTemplateVarsOutput as shown in the API docs and have added the modx-> part to make it work but now all I get for output is the word "Array". I have tried assigning the variable $idnames to the name of the TV--event_date and that won’t work.

          This I am afraid is really starting to show the short limits of my PHP wherewithal.

          Any further corrections, hints or tips would be great. Maybe even an article on reading API’s or using the API correctly.

          Cheers,

          Jay
            Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            If you just get the word "Array" that means that the result is an array. Test it with
            $arr = $modx->getTemplateVarsOutput( whatever );
            echo "<pre>";
            print_r($arr);
            echo "</pre>";
            

            to see what the keys and values are. Then you can refer to the ones you want.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 7231
              • 4,205 Posts
              &eFormOnBeforeMailSent I think is the event that you would use here.

              ThegetTemplateVarOutput takes the following parameters:
              $modx -> getTemplateVarOutput( TV name, document ID, published state );


              I am still not too sure how to go about this, I do see that FDM can save unpub dates, this is included in the db class and I was able to hard code a value. But I did not recognize any function to address this in the FDM class (I don’t really understand classes so it could be there). As I said I don’t understand classes, but in theory you should be able to add this in with a few lines, there is code to set the pub date so I would try to copy and modify it to accommodate the unpub date value.

              NewsPublisher seems to record unpublish dates, you should be able to edit it on the fly by modifying this line to do the math:

               $unpub_date = $_POST['unpub_date'];


              Maybe something like $unpub_date = ($_POST[’eventDate]+86400); or something like that.
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 27708 MODX Staff
                • 2,502 Posts
                Susan, Thanks. I needed to spend some time in the PHP Manual but it worked and now here is where I am at:
                function InsertUnPubDate($data) {
                	global $modx;
                	$table_name = $modx->getFullTableName( 'site_content' );
                	$fields = $data['unpub_date']);
                	$modx->db->insert( $fields, $table_name);
                }
                $arr = $modx->getTemplateVarOutput('event_date');
                $aday = 84600;
                $edate = $arr[event_date];
                $data = $edate + $aday;
                if (!isset($edate))
                exit();
                else InsertUnPubDate($data);
                

                Any more direction or correction or other stuff to look at to get there would be great. smiley
                  Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Just that you should always enclose strings in array keys with quotes
                  $edate = $arr['event_date'];

                  Ok, after looking at it more, the $data is not an array.
                  	$fields = $data['unpub_date']);

                  that db->insert function has always given me grief. I think what you need to do is to create an array, with the key being the field name and the value being $data.
                  $fields = array('unpub_date' => $data);

                  or something like that...
                  You’ll also need a parameter to indicate a WHERE clause in the INSERT query to specify which document ID to do this to...
                     function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "")
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 27708 MODX Staff
                    • 2,502 Posts
                    Susan,

                    Thanks again. I can get the data as a snippet call as below:

                    <?php
                    $arr = $modx->getTemplateVarOutput('event_date');
                    $aday = 84600;
                    $edate = $arr['event_date'];
                    $data = $edate + $aday;
                    echo '<pre>' . $edate. ' </pre>';//Just to see if the difference works to reassure me.
                    echo '<pre>' . $data . ' </pre>'; //Returns calculated unixtime value.
                    ?>
                    

                    This is all well and good but the issue I have is that the OnDocFormSave event occurs before the data is saved to the DB. Nothing is getting entered into the db in the unpub_date field in the db. So either there is no data to retrieve because the form has not been posted to the db or I need to actually use an event that occurs after the write to db happens although since there is an OnBeforeDocFormSave I would assume that the db write actually occurs. I just wonder if it is the INSERT order in MODx that is the issue.

                    Any further help or possibly some insight into this from you, Jason or other people intimate with the db insert order for documents.

                    Thanks for all your help,

                    Jay
                      Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Well, like I said, this function usually gives me grief, and I generally lose patience with it and just make the query myself and use $modx->db->query. Very bad of me, I know... Hopefully somebody with a better understanding of this insert() function will chime in with how to get the data into the field.

                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org