I am trying to modify some of the document data prior to it being saved using a plugin and the OnBeforeDocFormSave event.
Any ideas on how to accomplish this? I tried modifying $_POST to now avail.
I might have just been to tired last night when working on this but couldn’t find any clues here in the forums on how this is done.
-
☆ A M B ☆
- 24,524 Posts
The POST values are all pre-processed and loaded into variables; it’s these variables that are used in the insert/update queries. Since they are local variables, they aren’t available to the plugin (which is basically the invokeEvent() function). So in your plugin you have to declare all those variables you want to modify as global:
global $introtext,$content,$pagetitle ...
Then you can modify them.
-
☆ A M B ☆
- 80 Posts
Thanks for this information about declaring the variables as global. I’ve been using table edits in OnDocFormSave because I couldn’t figure this out. I’m going to try to rewrite my two little plugins with this information.
Again, huge thanks to you, Susan!
Time is what keeps everything from happening all at once.
Thanks, I knew it had to be something easy like that.
I guess one other question I have then is template variables... do they become variables like this also and if so are they just the name of the tv or something different. In the $_POST I noticed they were not the name of the tv but something different (can’t remember exactly and can’t look right now what I thought they were).
-
☆ A M B ☆
- 24,524 Posts
TVs are gathered up and loaded into a two-dimensional array named $tvChanges
$tvChanges[] = array('tmplvarid' => $tvId, 'contentid' => $key, 'value' => $modx->db->escape($tvVal));
Awesome, you have been a great help.
This is really going to make my life easier. I needed to use this to pull in data from itunes and populate a document.
After some work on this I found that the template variable array that you need to modify is actually $tmplvars
-
☆ A M B ☆
- 24,524 Posts
Of course. Now that you mention it, the values in $tmplvars aren’t processed into the $tvChanges array until after the new document has been saved, since it also makes use of the new document’s ID. Sorry about that!