We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3478
    • 10 Posts
    hello,

    i’ve searched a lot in the forum/wiki/docs and actually i can only read a TV when a document is already created but i can’t read a TV when creating a NEW document.

    $e = &$modx->Event;
    if($e->name == 'OnBeforeDocFormSave'){
    global $tags;
    if($id == "") $id = $modx->documentIdentifier;
    $tv = $modx->getTemplateVar('tags', '*', $id, 0);
    $tags = $tv['value'];
    $e->alert($tags);
    $modx->sendRedirect("index.php");
    exit;
    }


    instead i can read a default field such as "$content".

    $e = &$modx->Event;
    if($e->name == 'OnBeforeDocFormSave'){
    global $content;
    $e->alert($content);
    $modx->sendRedirect("index.php");
    exit;
    }


    i think the problem is that with a NEW document $id == "".

    is it possible to get a TV before saving a new document?

    thx!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      No. How can it? Before the document is created, it has no ID to use in the database to indicate the content of the TV for that document.

      However, you should be able to access the POST value for the TV from the form.
        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
        • 3478
        • 10 Posts
        thanks to:

        http://www.sottwell.com/how-template-variables-work.html

        i’ve learned how to get TV before saving a NEW document. now my code is:

        if($modx->Event->name == 'OnBeforeDocFormSave'){
        global $tv;
        $tv = $_POST['tvtags'];
        $modx->Event->Alert($tv);
        $modx->sendRedirect("index.php");
        exit;
        }


        do you know a debugging tool for modx POST/GET/SESSION variables?

        cheers!
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Well, I always use
          echo "<pre>";
          print_r($_POST) // whatever array or object you want to see here
          echo "</pre>";
          // if you want to just see the values above 
          // you can add a line to stop further processing
          // exit();
          

            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
            • 3478
            • 10 Posts
            thank you!
              • 34017
              • 898 Posts
              I’ve created a little function I use for this.
              function print_me($var, $exit = 0) {
                  echo '<pre>';
                  print_r($var);
                  echo '</pre>';
              
                  if ($exit == '1') {
                      exit();
                  }
              }
              


              And you can call it print_me($_POST); or print_me($_POST, 1);
                Chuck the Trukk
                ProWebscape.com :: Nashville-WebDesign.com
                - - - - - - - -
                What are TV's? Here's some info below.
                http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
                • 3478
                • 10 Posts
                how can i see POST/GET/SESSION during a plugin execution?

                i’m trying this but doesn’t work:

                function print_me($var, $exit = 0) {
                    echo '<pre>';
                    print_r($var);
                    echo '</pre>';
                
                    if ($exit == '1') {
                        exit();
                    }
                }
                
                switch($modx->Event->name){
                case 'OnBeforeDocFormSave' :
                global $tv;
                global $pm;
                $tv = $_POST['tvtags'];
                $pm = print_me($_POST);
                $modx->Event->Alert($tv.'<br>'.$pm);
                $modx->sendRedirect("index.php");
                break;
                }


                thx!
                  • 34017
                  • 898 Posts
                  Does the ’$pm = print_me($_POST);’ work?
                  Does it work without the function? Does the event get logged?
                    Chuck the Trukk
                    ProWebscape.com :: Nashville-WebDesign.com
                    - - - - - - - -
                    What are TV's? Here's some info below.
                    http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                    http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Did you check the onBeforeDocFormSave event in your plugin’s System Events tab?

                    I tried your code, and if I set the second paramater in the print_me function call
                    $pm = print_me($_POST, 1);

                    I get a lovely long array of POST values:
                    Array
                    (
                    [a] => 5
                    [id] =>
                    [mode] => 4
                    [MAX_FILE_SIZE] => 1048576
                    [refresh_preview] => 0
                    [newtemplate] =>
                    [stay] =>
                    [pagetitle] => Testing
                    [longtitle] => Test document
                    [description] =>
                    [alias] => testing
                    [link_attributes] =>
                    [introtext] =>
                    [template] => 3
                    [menutitle] => Testing
                    [menuindex] => 3
                    [hidemenucheck] => on
                    [hidemenu] => 0
                    [parent] => 0
                    [isfolder] => 0
                    [richtextcheck] => on
                    [richtext] => 1
                    [donthitcheck] => on
                    [donthit] => 0
                    [published] => 0
                    [pub_date] =>
                    [unpub_date] =>
                    [searchablecheck] => on
                    [searchable] => 1
                    [cacheablecheck] => on
                    [cacheable] => 1
                    [syncsitecheck] => on
                    [syncsite] => 1
                    [contentType] => text/html
                    [content_dispo] => 0
                    [type] => document
                    [ta] =>

                    This is a test.

                    [which_editor] => TinyMCE
                    [tvkeywords] => MODx, CMS, CMF, content, management, content management, framework
                    [save] => Submit Query
                    )
                      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
                      • 3478
                      • 10 Posts
                      if i set the second parameter in the "print_me()" the function works perfectly.

                      thank you all.