We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42364
    • 8 Posts
    Hello there,
    i am currently struggeling with a custom made Snippet to custom-validate a value from a Form-It Form.
    I need to validate if the serial no entered has a correct syntax.
    I must admit that I am more a designer than a programmer.

    My form:
    [[!FormIt?
    &hooks=`spam,email,redirect`
    &emailTpl=`sentEmailTpl`
    &emailSubject=`[[+datestamp_submitted]] | [[+contact_subject]]`
    &emailTo=`[email protected]`
    &emailCC=`[email protected]`
    &customValidators=`serialno`
    &validate=`snno:serialno`
    &redirectTo=`4`
    ]]


    My serialno-snippet:
    <?php
    $valuein=$mcsnno;
    $date=$valuein{4};
    if($date===x xor $date===y){
        return true;
    
    }else{
        $errorMsg = 'Wrong!';
        $validator->addError('mcsnno',$errorMsg);
        return false;
    }


    My problem now is:
    When running a .php file of the snippet on the same server it perfectly works.
    When running the snippet, it always returns the error Msg.

    Who can help?
    What do I do wrong?

    Many thanks in advance.

    BR
    Aviator
      • 40045
      • 534 Posts
      Hm, not sure about it, but according to http://rtfm.modx.com/display/ADDON/FormIt.Validators the field value that is posted (and validated by FormIt) is accessible through $value inside custom validators, so your validator snippet should probably look something like:

      <?php
      $valuein=$value;
      $date=$valuein{4};
      if($date===x xor $date===y){
          return true;
       
      }else{
          $errorMsg = 'Wrong!';
          $validator->addError('mcsnno',$errorMsg);
          return false;
      }
      
        • 42364
        • 8 Posts
        YES! U made my day.
        Many thanks.

        Merry X-MAS