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.

Form Questions /

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

Custom validation


Go to End


3 Posts   1295 Views

Avatar
danzzz

Community Member, 175 Posts

12 March 2011 at 8:22am

hi there,

My users can decide if they want receive money via paypal or banktransfer. There is a dropdownfield where users can choose
between this 2 options. Only if a user choose paypal I want to check if there is a paypal emailadresse and if it's correct (syntax).
And I only want to check if users filled out their bank data if they choosed banktransfer as payment type.

So I subclassed TextField because I need a custom validation. But in my custom validation I also need the value(s) from other form fields, as described above.

In this schema ...

class PaypalEmailField extends TextField {
function validate($validator) {
...
}
}

... I only have access to 1 formfield.

How to make all form fields accessable in the validator function?

To add the validation I use "new RequiredFields" ... but some fields are only required if other fields have special values :-)

anybody dealed with this problematic yet?

thx

Avatar
danzzz

Community Member, 175 Posts

12 March 2011 at 8:33am

Avatar
swaiba

Forum Moderator, 1899 Posts

12 March 2011 at 8:34am

I'd deal with this within the form action function before doing a redirect (or whatever action), or if in the CMS I'd use a custom validator for the data object being saved.