-
- 786 Posts
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.
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.
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.
-
- 786 Posts
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).
TVs are gathered up and loaded into a two-dimensional array named $tvChanges
$tvChanges[] = array('tmplvarid' => $tvId, 'contentid' => $key, 'value' => $modx->db->escape($tvVal));
-
- 786 Posts
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.
-
- 786 Posts
After some work on this I found that the template variable array that you need to modify is actually $tmplvars
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!