Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » [SOLVED] validation disabling hell

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

Page: 1 2
Go to End
Author Topic: 3373 Views
  • Entar
    Avatar
    Community Member
    19 Posts

    [SOLVED] validation disabling hell Link to this post

    well, I just want to COMPLETELY disable JavaScript validation in my form, I've tried around 5-6 different ways to do it, including core hacks - no way. What I achieved is removing of Behavior parts, script includes are still on their place. Here's what I am doing:

       function Form() {
          $fields = new FieldSet(
             new CompositeField(
                new HeaderField(_t('Member.MAINDATA', "Main data")),
                new EmailField("Email", _t('Member.EMAIL', "Email", PR_MEDIUM, 'Noun')),
                new PasswordField("Password", _t('Member.PASSWORD', 'Password'))
             )
          );

          ...
          //pushing many other fields
          ...

          $actions = new FieldSet(
             new FormAction('register', 'Register')
          );

          $requiredFields = new RequiredFields();
          $requiredFields->removeValidation(); // first way
          $requiredFields->setJavascriptValidationHandler('none'); // second way - not working at all, figured out this var is always set to "prototype" in the end
          $requiredFields->set_javascript_validation_handler('none'); // works, but "Valdator.js" and company includes are still here

          $form = new Form($this, 'Form', $fields, $actions, $requiredFields);
          return $form;
       }

    Question - how can I remove everything connected with prototype from my form? All my efforts end with JavaScript includes still here...

    Another interesting thing is when I completely wiped out "includeJavascriptValidation" method from Validator it continues to add includes... Why the hell? Cache? Perhaps I just don't get it...

    And another thing - is double call of "includeJavascriptValidation" really needed in Form.php? Found it in "FormAttributes" and "formHtmlContent"...

    My version is 2.3.0 stable, if it does matter. Thanks!

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: [SOLVED] validation disabling hell Link to this post

    The documentation for Validator::set_javascript_validatoin_handler() states:
    This could be called from _config.php to set site-wide javascript validation, or from ContentController::init() to affect only the front-end site.

    What it actually means: This has to be called before the validator is instanciated.. have a look at Validator::__construct().

    I've rectified this a bit in http://open.silverstripe.com/changeset/72373 - should make its way into the next minor release.
    To completely disable js validation on all forms, it should be sufficient to set the following in your mysite/_config.php:
    Validator::set_javascript_validation_handler('none');
    Thats assuming you're working on trunk or branches/2.3 - or wait for the next minor release ;)

    We're aware the current validation system is ... suboptimal, and hope to find time for a bit more pluggable architecture in 2.4, specifically around removing dependencies to Validator.js. You can see some early-stage discussion at: http://open.silverstripe.com/wiki/development/validation

  • Entar
    Avatar
    Community Member
    19 Posts

    Re: [SOLVED] validation disabling hell Link to this post

    hi Ingo, I don't want to disable it site-wide, just on particular form. So that's why I'm trying all that code below in form creation method. of course I know about disabling in config.

    p.s: I didn't find a way to disable includes in that document you sent link for...

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: [SOLVED] validation disabling hell Link to this post

    The document is just brainstorming, not user/dev documentation.

    You can disable on form-by-form instance with the following:
    $validator = new RequiredFields();
    $validator->setJavascriptValidationHandler('none');
    $form = new Form($this,'Form',new FieldSet(), new FieldSet(), $validator);

    Keep in mind, you'll need branches/2.3 or daily builds for this to work consistently, as it relies on the fixes i've mentioned earlier.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: [SOLVED] validation disabling hell Link to this post

    The document is just brainstorming, not user/dev documentation.

    You can disable on form-by-form instance with the following:
    $validator = new RequiredFields();
    $validator->setJavascriptValidationHandler('none');
    $form = new Form($this,'Form',new FieldSet(), new FieldSet(), $validator);

    Keep in mind, you'll need branches/2.3 or daily builds for this to work consistently, as it relies on the fixes i've mentioned earlier.

  • Entar
    Avatar
    Community Member
    19 Posts

    Re: [SOLVED] validation disabling hell Link to this post

          $requiredFields = new RequiredFields();
          $requiredFields->setJavascriptValidationHandler('none');

          $form = new Form($this, 'Form', $fields, $actions, $requiredFields);

    not working

          $requiredFields = new RequiredFields();
          $requiredFields->set_javascript_validation_handler('none');

          $form = new Form($this, 'Form', $fields, $actions, $requiredFields);

    working

    I am using version from http://open.silverstripe.com/changeset/72373 and yes, it's 2.3.0 from downloads page stable.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: [SOLVED] validation disabling hell Link to this post

    > I am using version from http://open.silverstripe.com/changeset/72373 and yes, it's 2.3.0 from downloads page stable.

    Thats kinda contradictory - are you using a subversion checkout of trunk on r72373, or a 2.3.0 stable download? Or did you patch your 2.3.0 with this specific fix? I've tried this specific notation before applying the patch, worked fine for me.

    > $requiredFields->set_javascript_validation_handler('none');
    Thats just using a static method as an instance method, which is sadly possible in PHP5. Should have the same effect as globally disabling validation.

  • Entar
    Avatar
    Community Member
    19 Posts

    Re: [SOLVED] validation disabling hell Link to this post

    > Or did you patch your 2.3.0 with this specific fix? I've tried this specific notation before applying the patch, worked fine for me.

    It is clean 2.3.0 setup just patched Validator.php (actually replaced original with r72373).

    > Thats just using a static method as an instance method, which is sadly possible in PHP5. Should have the same effect as globally disabling validation.

    Not good for me then

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