We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1209
    • 49 Posts
    Hello.
    I have a TV [tt]’EndDate’[/tt]. I want to set the [tt]unpub_date[/tt] to the value of that TV each time I save the document.

    Events: OnBeforeDocFormSave
    
    $dateObj = $modx->documentObject['EndDate'];
    $date = $dateObj[1];
    $modx->documentObject['unpub_date'] = $date;


    [tt]unpub_date[/tt] remains empty. Why?
      • 27376
      • 576 Posts
      OnBeforeDocFormSave doesn’t use the $modx->documentObject. Try using the following code:
      <?php
      global $tmplvars;
      global $unpub_date;
      
      $unpub_date = is_array($tmplvars['EndDate']) ? $tmplvars['EndDate'][1] : $tmplvars['EndDate'];
      
      Code is untested, so it may take some tweaking, but you get the idea. Check out [tt]manager/processors/save_content.processor.php[/tt] (starting at/around line 172) for more information.
        • 1209
        • 49 Posts
        That is what appears when I push the "Save" button in the document edit form.

        An error occured while attempting to save the edited document. The generated SQL is: UPDATE `fengshui_feng`.`modx_site_content` SET introtext='', content='', pagetitle='? 05 ?? 08 ??? 2007 ????', longtitle='? 05 ?? 08 ??? 2007 ????', type='document', description='', alias='5-8-may-2007', link_attributes='', isfolder=0, richtext=1, published=1, pub_date=0, unpub_date=, parent=163, template=7, menuindex='0', searchable=1, cacheable=0, editedby=1, editedon=1176885088, publishedon=publishedon, publishedby=publishedby, contentType='text/html', content_dispo='0', donthit='0', menutitle='', hidemenu='0' WHERE id=164; .
        Warning: Cannot modify header information - headers already sent by (output started at /home/fengshui/domains/feng-shui.ru/public_html/gamma/manager/processors/save_content.processor.php:428) in /home/fengshui/domains/feng-shui.ru/public_html/gamma/manager/processors/save_content.processor.php on line 563
        


        In the first line we see that [tt]unpub_date[/tt] is no longer 0. Also if I simply put in the plugin [tt]$unpub_date = ’xxx’;[/tt], then this ’xxx’ appears in the message above.

        Conclusion:

        • The TV retrieval gives empty string;
        • The plugin pushes the header() function after it has been already fired.
          • 27376
          • 576 Posts
          It appears that the [tt]$unpub_variable[/tt] was empty when you tried to save. That’s why the error popped up. A couple things to keep in mind while your doing this:

          • You should propably implement some checking to make sure that the variable you’re replacing unpub_date with is NOT empty.
          • Also, remember that [tt]unpub_date[/tt] MUST be a unix timestamp.