Jump to main content Jump to doc navigation

Event: 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:

$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?");

Such a plugin will write to the "Error log" whether a new chunk was created or an existing one was updated:

$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';

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.


  • modmore
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Digital Penguin
  • Dannevang Digital
  • Sepia River Studios
  • Chris Fickling
  • CrewMark
  • deJaya
  • Following Sea
  • Anton Tarasov
  • eydolan
  • Raffy
  • Lefthandmedia
  • Murray Wood
  • Snow Creative
  • Nick Clark
  • Helen
  • JT Skaggs
  • krisznet
  • YJ
  • Yanni
  • Richard


$367 per month—let's make that $500!

Learn more