Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Custom validation

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

Page: 1
Go to End
Author Topic: 736 Views
  • danzzz
    Avatar
    Community Member
    175 Posts

    Custom validation Link to this post

    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

  • danzzz
    Avatar
    Community Member
    175 Posts

    Re: Custom validation Link to this post

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Custom validation Link to this post

    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.

    736 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.