We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13808
    • 61 Posts
    I'm looking to get a custom validator working with a form I'm building via FormItBuilder.
    (Revo 2.2.4-pl with FormItBuilder 1.3.2-pl)

    I keep receiving an error when I try to do the following:
    $ucup_formRules[] = new FormRule('wordCountUnder150', $ucup_fe_letter);

    The error is
    Fatal error: Uncaught exception 'Exception' with message 'Type "wordCountUnder150" not valid.
    which implies to me I need to somehow create a rule type. Any leads on how to do that?

    Based on what I could glean from the FormIt.Validators documentation, I thought I may have been doing that by including
    $ucup_form->setCustomValidators('wordCountUnder150');

    I'd also tried
    $ucup_form->setValidate('wordCountUnder150');

    The contents of wordCountUnder150 seems irrelevant at this stage because it errors even if the only contents are
    <?php
    return true;

    Can anyone provide any guidance on what I might be doing wrong here?

    (I am aware of the custom validator documentation at http://modxrevo.datawebnet.com.au/adding-your-own-custom-validation but was hoping to do this with a custom validator rather than a hook if that's possible.)
      • 18270
      • 68 Posts
      Hi Josh,
      If you look at how to do this in FormIt alone here
      http://rtfm.modx.com/display/ADDON/FormIt.Validators
      you will see that when makign a custom validator you need to first define the custom validators by using something like this
      [[!FormIt? &customValidators=`isBigEnough`]]

      you then need to actually define how to use the validator like this
      [[!FormIt? &validate=`cost:isBigEnough`]]


      FormItBuilder should allow you to set both of these properties together using both the methods you mentioned in your post however they both need to be used together.
      $ucup_form->setCustomValidators('wordCountUnder150');
      $ucup_form->setValidate('mytextarea:wordCountUnder150');
      


      you would then write your snippet as shown in the FormIt documentation.

      Feel free to contact me via
      http://modxrevo.datawebnet.com.au/contact-support/
      if you need assistance.