XF 2.2 How to cancel a save in _preSave() after validation

AndrewSimm

Well-known member
I would like to be able to perform some validation to prevent duplicate entries in _preSave and not save if a duplicate exists. Is there a function I can use to tell the entity to slip this one?

edit: It is worth adding some context. I am saving from an array so I don't want to error out the entire process, but rather just skip the duplicate lines.
 
The only thing you can do in pre-save is to trigger an error if you know the save is going to fail. Your calling code can check this (by calling pre-save before explicitly calling save) and skipping the save action if there are errors.
 
Top Bottom