Closed jdoubleu closed 2 years ago
Hey @jdoubleu
Have you tried this? https://typerocket.com/add-custom-field-validation-to-wordpress-post-types/
Thanks, this makes it a little bit better. The Fields class and the controller method make it easier/clearer to validate the fields.
Unfortunately, I still couldn't find a way to prevent WordPress from saving the post at all. The onValidateSave
method is called from the save_post
action, which is definitely too late. I'm not sure which, if there is one at all, hook to intercept to prevent a post from being saved initially.
You may also want to link to this tutorial/guide from the documentation?
I've updated the docs for this one.
It would be nice, if I could easily add validation rules to my custom post type's model, like in http fields.
I imagine something like a
$rules
array, next to the$fillable
array, in a WPPost derived class.So, when I create a new custom post type and add a form to it in the backend (e.g. with
setTitleForm
), I would like to validate the fields (e.g. require some of them).My current workaround is to create a controller, overwrite its
update
function and manually trigger the validator in there. However, this doesn't properly work, the user won't get any feedback, because of #235.