You want OnBefore... The other event happens after the object is saved to the DB. The rest of the code looks right to me.
-
☆ A M B ☆
- 450 Posts
OK. A couple of follow-up questions.
1. OnBefore was my first instinct... but When I activate the plugin set to OnBefore, my documents never save, I get the endless "Please Wait..." message.
2. Thinking ahead, if I do manage to fire the code as written in an OnBefore event... wouldn’t the actual OnDocSave event overwrite the pagetitle field anyway? Maybe what I’m really trying to do does need to happen after the object is saved to the db... save what they input into the form, then test the value and modify if needed(?)
-
☆ A M B ☆
- 450 Posts
Figured it out.
I don’t want "$modx->resource".
I just want "$resource"
These events (OnBeforeDocFormSave & OnDocFormSave) have an Event Parameter called "resource" that points to the modResource object being handled by the form.
This has been another episode of "James posting to the forums before reading all available documentation".
Sorry, I should have noticed that.
I know it is quite an old Discussion, but I just read it and want to add that the line:
is not necessary.
The Resource will be saved in the next step anyways.
MODX Rocks I am so glad that I have found it.
That line is necessary if the the plugin is connected to OnDocFormSave, which fires after the doc is saved. It's not necessary if you're connecting to OnBeforeDocFormSave.