Topic: Is it possible to change values when a document is saved in the manager?  (Read 2230 times)

Pages: [1]   Go Down

#1: 26-Dec-2005, 06:59 AM

Mitch
Posts: 234

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?

#2: 26-Dec-2005, 07:12 AM

Moderators
madmage
Posts: 167

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

#3: 26-Dec-2005, 09:20 AM

Foundation

rthrash
Posts: 11,348

WWW
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!

MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#4: 29-Dec-2005, 03:34 AM

Emeritus
xwisdom
Posts: 1,732

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.

#5: 29-Dec-2005, 08:37 AM

Emeritus
Djamoer
Posts: 1,495

No one can limit a man other than the man himself.

WWW
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...

#6: 3-Jan-2006, 02:10 PM

Mitch
Posts: 234

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.

Code:
$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.");
    }
  }
}
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.