Jump to:

10930 Posts in 2613 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » NetefxValidator

Discuss all other Modules here.

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

Page: 1 2 3
Go to End
Author Topic: 4320 Views
  • lx
    Avatar
    Community Member
    82 Posts

    NetefxValidator Link to this post

    Hi all,

    we released a module for validation, which also works in Modeladmin.
    It gives you more possibilities than RequiredFields but has no javascript validation (at this time).

    You can download it here:
    http://www.netefx.de/Silverstripe-NetefxValidator.php

    You will also find a detailed documentation there.

    Use this forum thread for questions and comments on the module.

    lx

  • lx
    Avatar
    Community Member
    82 Posts

    Re: NetefxValidator Link to this post

    Hi,

    we added some usefull rules.
    So NetefxValidator 0.4 can be downloaded now.
    http://www.netefx.de/Silverstripe-NetefxValidator.php

    Whats new?

    1) new rule "ISONEFROM"

    if you have a dropdownfield you can define a number of elements which return TRUE if you choose one of them. This can be used for example in DataObjects that are Translatable. So maybe in each language your dropdownfield has one option that should return TRUE. But now you can define a validationrule that contains the IDs for the "good" options of all languages.

    2) new rule "ISNOTONEFROM"

    Of course its just the opposite of ISONEFROM. If one of these values is selected, the rule returns FALSE.

    3) new rule "MINCHARACTERS"

    easy to eyplain: if the users fills less than x letters, the validatorrule returns FALSE
    example:

    $rule_FirstName_MinChar = new NetefxValidatorRule("FirstName", "MINCHARACTERS", array('2'), "Please enter at least two characters");

    Note: this can also be done with REGEXP rules, which were already available in 0.3 . But MINCHARACTERS is easier to use.

    4) new rule "MAXCHARACTERS"

    similar to "MINCHARACTERS"

    5) new rule "CHARACTERSBETWEEN"

    gives you the possibility to define MIN and MAX in one rule.

    $rule_FirstName_CharBetween = new NetefxValidatorRule("FirstName", "CHARACTERSBETWEEN", array('2','20'), "Please enter between 2 and 20 characters");

    6) new rule "XOR"

    the new XOR rule belongs to the set of rule combinations.
    A XOR rule validates, if and only if exactly one of the two rules, which are given as parameter, validates.

    7) updated documentation:

    - forgotten to mention the rules "DateIsMinDaysAfterToday" and "DateIsMinDaysBeforeToday"
    - better example for own validation functions.

    so, i am wayting for the first feedback.
    lx

  • s!m
    Avatar
    Community Member
    9 Posts

    Re: NetefxValidator Link to this post

    Hi lx,

    I would like to thank you for releasing this very useful module.

    The possibility to call own functions for validation is really great and is one of the things I was missing in Silverstripe/Sapphire.

    Have you tested your validator in DOM-Popups? I've got it working, but if validation fails, the form-content is missing, so on any error you've got through validation you have to reenter all details in the form...
    Maybe there's something I forgot? All I did, was to extend from DataObjectManager_Popup, implement the validator-stuff in its constructor and let my DataObjectManager use this custom Popup-class...

    Anyway, thanks again for this module,

    Greetings,
    s!m

    PS: There might be a small error in your documentation, I think in the part about Function-Rules, this example

    class MyLibrary {

    public function MySpecialValidationFunction ($data, $args) {
    ...


    should probably be static...

    class MyLibrary {

    public static function MySpecialValidationFunction ($data, $args) {
    ...

  • lx
    Avatar
    Community Member
    82 Posts

    Re: NetefxValidator Link to this post

    Hi s!m,

    thanks for your answer.

    I didnt test it in DOM, because I dont use the DataObjectManager.
    Is RequiredFields() working correctly in DOM?

    You are right. This is an error in the documentation.
    I will fix it asap.

    Bye
    lx

  • s!m
    Avatar
    Community Member
    9 Posts

    Re: NetefxValidator Link to this post

    Hi lx,

    RequiredFields aren't working either, so the problem is not your module, thanks for your hint...

    Best regards,
    s!m

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: NetefxValidator Link to this post

    Hi, lx,

    Great Module, and thanks for pointing me to this thread. Exactly what I needed.

    Im having an issue with "OR" rules though. This looks correct according to the documentation, but the field is not validating any of the rules.

    Any ideas?

    - - - - -
    UPDATE:
    It appears that the OR rule doesn't play nice with the UNIQUE rule.

    If I separate the UNIQUE rule from the OR rule it works fine.
    - - - - -

    $rule_FirstName_Required = new NetefxValidatorRule("FirstName", "REQUIRED", "", "A first name is required");

    $rule_LastName_Required = new NetefxValidatorRule("LastName", "REQUIRED", "", "A surname or last name is required");
          
    $rule_Email_Unique = new NetefxValidatorRule("Email", "UNIQUE", array('Email','LandingFormSubmission'), "no message");

    $rule_Email_Required = new NetefxValidatorRule("Email", "REQUIRED", "", "no message");

    $rule_Email_Valid = new NetefxValidatorRule("Email", "REGEXP", array("/[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]/"), "no message");

    $rule_Email = new NetefxValidatorRule("Email", "OR", array($rule_Email_Unique,$rule_Email_Required,$rule_Email_Valid), "Email must be valid and only one email per registration may be used");

    $validator = new NetefxValidator($rule_FirstName_Required, $rule_LastName_Required, $rule_Email);

    Thanks!
    Chris.b

  • lx
    Avatar
    Community Member
    82 Posts

    Re: NetefxValidator Link to this post

    Hi Prawnstar,

    First I have to mention that logical rules do only combine 2 rules (not 3 at once).

    But in your form i dont think that you really want an OR combination,
    because I think Email is REQUIRED AND has to be UNIQUE AND has to be valid, right ?

    So just add all these 3 rules to your NetefxValidator (without the need to logically combine them).
    Make sure , that the REQUIRED rule is the last rule you add to the validator.)

    If you really want to combine 3 rules with OR you have to combine 2 of them with OR and then combine the third with the combined rule of 1 and 2. (In such a case you come to a point where logically rule combination is getting difficult and needs a lot of concentration. These are at least my experiences

    I hope this helped you
    lx

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: NetefxValidator Link to this post

    Ah! You're correct. That would be AND, not OR.

    That makes total sense, thanks!

    Chris.b

    4320 Views
Page: 1 2 3
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.