OnBeforeChunkFormSave
Last updated Apr 12th, 2019 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$306 per month—let's make that $500!
Learn moreEvent: OnBeforeChunkFormSave¶
Fires after a form is submitted but before a Chunk is saved in the manager.
- Service: 1 - Parser Service Events
- Group: Chunks
Event Parameters¶
Name | Description |
---|---|
mode | Either 'upd' or 'new', depending on the circumstance. |
chunk | A reference to the modChunk object. |
id | The ID of the chunk. Will be 0 for new chunks. |
Examples of¶
Such a plugin will display a message if the description field is not filled:
<?php
$eventName = $modx->event->name;
switch($eventName) {
case 'OnBeforeChunkFormSave':
//if we update an existing chunk
if ($mode == modSystemEvent::MODE_UPD){
//if description is not filled
if (!$chunk->get('description')){
$modx->event->output("You haven't forgotten anything?");
}
}
break;
}
Such a plugin will write to the "Error log" whether a new chunk was created or an existing one was updated:
<?php
$eventName = $modx->event->name;
switch($eventName) {
case 'OnBeforeChunkFormSave':
if ($mode == modSystemEvent::MODE_UPD){
echo 'An existing chunk has been updated';
} elseif ($mode == modSystemEvent::MODE_NEW){
echo 'Chunk was created';
}
break;
}
See Also¶
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$306 per month—let's make that $500!
Learn more