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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

Custom validation


Go to End


3 Posts   1048 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.