May 17, 2008, 10:33 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Donate to MODx: Donations
Pages: [1]   Go Down
  Print  
Author Topic: Is it possible to change values when a document is saved in the manager?  (Read 1434 times)
0 Members and 1 Guest are viewing this topic.
Mitch
Full Member
***
Posts: 217


« on: Dec 26, 2005, 06:59 AM »

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?
Logged
madmage
Full Member
***
Posts: 146


« Reply #1 on: Dec 26, 2005, 07:12 AM »

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
Logged
rthrash
Foundation
*
Posts: 8,791



WWW
« Reply #2 on: Dec 26, 2005, 09:20 AM »

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!

Logged

MODx is a framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Community participation and questions are encouraged, especially when you help us help you, read the wiki, and review snippet parameters – even if you have to look at the source. Searching the forums helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
xwisdom
Foundation
*
Posts: 1,732



« Reply #3 on: Dec 29, 2005, 03:34 AM »

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']
Logged

xWisdom
www.xwisdomhtml.com
The fear of the Lord is the beginning of wisdom:
MODx Co-Founder - Create and do more with less.
Djamoer
Testers
*
Posts: 1,492

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


WWW
« Reply #4 on: Dec 29, 2005, 08:37 AM »

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

Mitch
Full Member
***
Posts: 217


« Reply #5 on: Jan 03, 2006, 02:10 PM »

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.");
    }
  }
}
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!