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 forum.silverstripe.org 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.

Archive /

Our old forums are still available as a read-only archive.

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

More than one Validator?


Go to End


2 Posts   1218 Views

Avatar
dio5

Community Member, 501 Posts

12 October 2008 at 9:27am

Edited: 13/10/2008 8:59am

I was wondering how I can specify more than one validator for a form?

Suppose I want to have RequiredFields, plus another validator of my own, how can I add this to a form?

As far as I can see, you can only pass one validator to the Form constructor, right? It won't accept an array of Validator objects I suppose... thus making this impossible?

Also, I was wondering what the point is of returning 'true' or 'false' in the php() method of Validator/RequiredFields? - it seems to me the only thing having a result is throwing a validationError() ?

And thirdly - is it possible to add a field to a form after the form has been created? - as on validation? (so when the failed form is returned?) In other words, change the form/add a field from within the validator? I don't think so but I might be wrong... I think I'll need to change/decorate the 'beforeProcessing' of Form somehow, or have a RedirectBack that lets me add a field.

Avatar
dio5

Community Member, 501 Posts

13 October 2008 at 9:55am

Nevermind, think I've found it... more or less.