This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

pymarco
pymarco

I am creating a custom plugin with backend form for a client. I need to validate the form fields, but cannot figure out how. I followed the model validation documentation by adding a $rules array to my model. Yet when I click save on my /create route it attempts to save in the db without throwing validation errors. Does FormController not do form validation? Do I need to override the default behavior for create/update? Thanks

Last updated

Flynsarmy
Flynsarmy

Your model class also needs a use \October\Rain\Database\Traits\Validation; line in it.

pymarco
pymarco

Thanks again @Flynsarmy. It works!

I'm a little new to traits, and previously I had try to add the use line outside of the class, but got an exception.

Last updated

Shahiem
Shahiem

Use it inside of the class. Like this

public Class
{
   use \October\Rain\Database\Traits\Validation;
 }

Last updated

Parsec
Parsec

And how to add custom validation messages in here? I've tried to add them in a $messages property, but it doesn't seem to be used.

Parsec
Parsec

I've found the answer in the docs. Add the property $customMessages

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.