Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

ModelAdmin - Intercept edit form submit

Go to End



Community Member, 1 Post

4 May 2016 at 3:13am

Edited: 04/05/2016 3:14am

There is following Notification DataObject

class Notification extends DataObject {

		private static $db = array (
			'Message'           => 'Text',

		private static $has_one = array(
			'Member'            => 'Member', //the recipient


The important part is the has_one relationship with a member. This can't be changed to a many_many relationship.
But, for practical reasons, I want our customer to be able to send a notification to multiple customers at once. Therefore I added the following fields to the notification objects getCMSfields method:

HeaderField::create('SentToHeader', 'Notification senden an...'),
ListboxField::create('Member', '...folgende Mitglieder', $members)->setMultiple(true),
ListboxField::create('Membership', '...Mitglieder folgender Mitgliedschaften', $memberships)->setMultiple(true),

So far, everything is fine.
Now I need to somehow intercept the submit and instead of creating a single notification, create notifications foreach selected member (or for each member in each selected membership). I don't wan't to do this in the notifications onBeforeWrite because I feel like this is a very hacky solution.

Now to my question:
Can I somehow intercept the forms submit event in my model admin and prevent it's default behavior (creating a single new notification) and instead create as many new notification objects as needed?

Thanks in advance