Jump to:

1969 Posts in 1272 Topics by 606 members

Form Questions

SilverStripe Forums » Form Questions » Requiredfields not working

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

Page: 1
Go to End
Author Topic: 1591 Views
  • Peter_SS
    Avatar
    Community Member
    19 Posts

    Requiredfields not working Link to this post

    Hi guys we updated our site to SS version 2.4 but the requiredfields on our forms are not working anymore. do you encounter this issue?

    here's our requiredfiield code.

    $validators = new RequiredFields( 'ID', 'Name', 'Name2', 'Email' );
    $validators->setJavascriptValidationHandler( 'none' );

    i also change the parameters for the requiredfields since in the constructor it requires array type and it's still not working
    $validators = new RequiredFields( array('ID', 'Name', 'Name2', 'Email'));
    $validators->setJavascriptValidationHandler( 'none' );

  • Gene
    Avatar
    Community Member
    41 Posts

    Re: Requiredfields not working Link to this post

    I'm having the same issue on 2.4.

    The validator seems to have no effect. EmailFields always seem to be required (even without the validator) and I can't make my TextFields required.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Requiredfields not working Link to this post

    I've not noticed this, which version did you come from and could you share a little more of the code... is this DOM (should be in the DOM section), ModelAdmin, Custom Form, etc?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Requiredfields not working Link to this post

    I've just tried this on branches/2.4, works as expected - with EmailField, and both argument/array constructor of RequiredFields.

  • Gene
    Avatar
    Community Member
    41 Posts

    Re: Requiredfields not working Link to this post

    I'm finding that the javascript validation works fine but if you turn off javascript or disable the javascript validator, the server side php validation is not being run (at least on frontend forms; I haven't tried in the CMS).

  • Gene
    Avatar
    Community Member
    41 Posts

    Re: Requiredfields not working Link to this post

    In case anybody else is having issues, the RequiredFields on my form were Checkboxes. There is a SS bug in which checkboxfields don't validate properly... http://open.silverstripe.org/ticket/6231

  • lx
    Avatar
    Community Member
    81 Posts

    Re: Requiredfields not working Link to this post

    Take a look at this: http://silverstripe.org/all-other-modules/show/16073

    I am not 100% sure , if this will work:

    $rule_MyCheckbox_Required = new NetefxValidatorRule("MyCheckbox", "REQUIRED", "", "You have to confirm this checkbox.");

    If it is not working either, you can use:

    $rule_MyCheckbox_Selected = new NetefxValidatorRule ("MyCheckbox", "TEXTIS", array("1"), "You have to confirm this checkbox.");

    Note: What is also possible is the validation of a checkboxfieldset.
    There is a build in function that lets you define the minimum number/maximum number of checkboxes that have to be checked.
    (this rule is not explicitly described in the documentation. i will add example code for this next week).

    1591 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.