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:

<?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

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

Budget

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

Learn more