We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19726
    • 239 Posts
    I am trying to make sure that my users fill in a longtitle when they create a document. My idea was to use the normal title for longtitle if they forgot to fill it in.

    I tried to make a plugin that acts on the OnBeforeDocSave event. So I could check if longitle was filled in. If not make the longtitle equal to the normal title. But I only get the id of the document beeing edited from the event. I don’t see a way to get access to the data that is going to be saved.

    Am I overlooking something or should I use another approach?
      • 17895
      • 209 Posts
      We developer REALLY NEED a plug-in documentation... I’m sorry to go on asking work... but this will BOOST the development of MODx, since not only the core developer will be aware of the hidden stuff of MODx
        Daniele "MadMage" Calisi
      • madmage, we really agree!

        This is an area that we want to do a much better job on and really help folks understand. And I promise that we’re working on it!

          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 32963
          • 1,732 Posts
          Quote from: Mitch at Dec 26, 2005, 12:59 PM

          I tried to make a plugin that acts on the OnBeforeDocSave event. So I could check if longitle was filled in. If not make the longtitle equal to the normal title. But I only get the id of the document beeing edited from the event. I don’t see a way to get access to the data that is going to be saved.

          The data that’s going to be saved can be found inside the $_POST variable. For example $_POST[’longtitle’]
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.
            • 32241
            • 1,495 Posts
            Yep, and you can change the content of that $_POST vars, so that you can fill out any values that you desired.

            Btw, how about us, the developer to start building documentation, for example madmage, it seems that you know quite a lot of it, so you can start making a really simple documentation for the doc team to polish it and expand it further.

            Don’t ask me to do it though, I’m kinda lazy in writing something, especially documentation.... LOL...
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 19726
              • 239 Posts
              I ended up with using the data from the $_POST on the OnDocFormSave event and then update the database if needed. I made a plugin called AutomaticLongtitle the code is pasted below. Remember to register the OnDocFormSave for this plugin if you decide to use it.

              $e = &$modx->Event;
              
              // Only on this event
              if ($e->name == 'OnDocFormSave')
              {
                // Check if the longtitle is empty
                if ($_POST['longtitle'] == '' && $_POST['pagetitle'] != '')
                {
                  $fields = array('longtitle' => $_POST['pagetitle']);
                  $table = $modx->getFullTableName('site_content');
                
                  // Update the database
                  $rows_affected = $modx->db->update(
                    $fields, 
                    $table,
                    "id = {$e->params['id']}"
                  );
              
                  // Generate an error if the DB was not updated
                  if(!$rows_affected)
                  {
                    $modx->event->alert("AutomaticLongtitle: An error occured when saving the longtitle.");
                  }
                }
              }