Custom events that are available

Custom events allow you to specify code that should be run either before or after data is added, edited or deleted.

Introduction

Since version 2, SQLite Edit for PHP has had the facility that allows you to register a function that gets run when certain things happen - events. These functions are registered by giving them as part of the configuration. The functions are just normal PHP functions so they can do anything that PHP functions can do, including call other functions if required.

The available events

There are events for before and after all the major operations, including:

beforeinsert This event is fired just before a new row is inserted into the table when users click on the add button. No extra data is passed to the listener function.

By returning false (it must be exactly false - not an empty string or zero) from the event listener function you can cancel the insert and no new row will be inserted.

'events' => [
    'beforeinsert' => function ($obj)
    {
        // No data gets passed to this event because there's nothing to pass!
    }
]
insert This event is fired after a new row has been inserted into the table. If you want the ID of the new row, you can get the last inserted auto-increment ID by calling the correct method on the database object (which is part of the SQLite Editor for PHP object) like this:
'events' => [
    'insert' => function ($obj)
    {
        $id = $obj->db->lastInsertID();
    }
]
beforeupdate This event is fired just before a row is updated - as a direct result of the user editing a row. If you've disabled editing there is no way for this event to be fired. Details of the row data that's about to be edited is passed to the event listener function.
'events' => [
    'beforeupdate' => function ($obj, $data)
    {
        // The $data variable that's passed to this
        // function as an argument is the updated data that's
        // submitted by the user. This variable looks like
        // this:
        //
        // array(
        //
        //   // The new data that's going to be set in the database.
        //   'data' => array(
        //       'name'     => 'Richard',
        //       'age'      => 34,
        //       'location' => 'UK'
        //   ),
        //
        //   // The name of the primary key column in the table.
        //   'editor_primary_key_column' => 'id',
        //
        //   // The value of the primary key for this row.
        //   'editor_primary_key_value'  => 123
        // )
        //
        // This query fetches the original row data, that's
        // being edited, from the database - the original,
        // unedited, data.
        //
        //$original = $obj->db->row(sprintf(
        //    "SELECT * FROM %s WHERE %s = %d LIMIT 1",
        //        $obj->database_table,
        //        $data['editor_primary_key_column'],
        //        $data['editor_primary_key_value']
        //));
        //
        // This is a debug function that's part of the source
        // code and prints the structure of the variable that's
        // given to it.
        //
        // p($original);
    }
]
If you want the original data you need to fetch it from the database. There's an example in the code above of doing that.

By returning false from the event listener function (it must be exactly false - not an empty string or zero) you can cause the update not to be saved to the database and abandoned instead. In this case, you may want to show an error message to the user which you can do with the editor_messages::* functions. More on those in the the API documentation.

By returning false (it must be exactly false - not an empty string or zero) from the event listener function you can cancel the update and the row will not be changed.

update This event is fired after the SQL query has been (successfully) run to update the database, when a user has submitted the edit form. If you haven't enabled editing there is no way for this event to be fired. Details of the updated row data is given to the event listener function.
'events' => [
    'update' => function ($obj, $data)
    {
        // The $data variable that's passed to this
        // function is the updated data that has been set
        // in the database. This variable looks like this:
        //
        // array(
        //
        //   // The new data that's been set in the database.
        //   'data' => array(
        //       'name'     => 'Richard',
        //       'age'      => 34,
        //       'location' => 'UK'
        //   ),
        //
        //   // The name of the primary key column in the table.
        //   'editor_primary_key_column' => 'id',
        //
        //   // The value of the primary key for this row.
        //   'editor_primary_key_value'  => 123
        // )
    }
]
beforedelete This event is fired just before a row is deleted. It's given an array of the row IDs that are going to be removed from the database. If you've disabled deleting there is no way for this event to be fired.
'events' => [
    'beforedelete' => function ($obj, $data)
    {
        // The $data variable that's passed to this
        // function contains an array of the IDs of the
        // rows that are about to be deleted. This variable
        // looks like this:
        //
        // array (
        //   'ids' => [1,2,3,4] // An array of the IDs of the rows that are about to be deleted
        // )
    }
]

By returning false (it must be exactly false - not an empty string or zero) from the event listener function you can cancel the delete and the row(s) will not be deleted. In this case, you may want to show an error message to the user which you can do with the editor_messages::* functions. More on those in the the API documentation.

delete This event is fired after the SQL query has been (successfully) run to delete one or more rows from the database. If you haven't enabled deleting there is no way for this event to be fired. An array of the IDs of the rows that were deleted is passed to the event listener function.
'events' => [
    'delete' => function ($obj, $data)
    {
        // The $data variable that's passed to this
        // function contains an array of the IDs of the
        // rows that were deleted. This variable
        // looks like this:
        //
        // array (
        //   'ids' => [1,2,3,4] // An array of the IDs of the rows that were deleted
        // )
    }
]

Last updated: 10th October 2026