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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Aborting a save in onbeforewrite:


Go to End


2 Posts   765 Views

Avatar
BigD1214

Community Member, 24 Posts

10 December 2013 at 7:49am

Hello,
Is there a way to abort a save if a condition in the onbeforewrite: function is not met? Please help!
Thanks so much!

Avatar
swaiba

Forum Moderator, 1899 Posts

17 December 2013 at 6:28am

Hi BigD1214,

As there is no return type the only suggestion I would have is to use "die()" there - but that is truly awful and you must be able to fix another way... probably using a validator...

This addresses their use within ModelAdmin...

http://www.silverstripe.org/general-questions/show/17007

And it is [kinda] the same for a form. Only directly in the code if you create / write will there be an issue -but hey you can call validation right there (either custom or reuse any validator you create)