We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29266
    • 12 Posts
    Hi. question is about "isNumber"

    &myField:required:isNumber => works fine.
    &myField:isNumber => keep’s geeving me an error, but the field is not required.

    How to send email with "isNumber" with empty "myField" field?
      • 4172
      • 5,888 Posts
      I didn’t test it, but I think you need a custom-validator-snippet with something like that:

      <?php
      
       $success = $value !='' && !is_numeric($value)?false:true; 
        
       if (!$success) {  
         // Note how we can add an error to the field here.  
         $validator->addError($key,$modx->lexicon('formit.not_number'));  
       }  
       return $success;  
      
      ?>
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 29266
        • 12 Posts
        It’s for my multilangual site. How to put error messages from lexicon in here?
          • 4172
          • 5,888 Posts
          you can try
          $modx->lexicon('formit.not_number')
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 29266
            • 12 Posts
            No’p, both didn’t work.
              • 4172
              • 5,888 Posts
              what do mean with ’both didn’t work’ ?
              what did you try?

              I tried it for you and all did work.
              created snippet with code above ’isEmptyOrNumber’

              [[!FormIt? 
              &hooks=`spam,email` 
              &emailTpl=`myEmailChunk` 
              &emailTo=`[email protected]`
              &customValidators=`isEmptyOrNumber`
              ]]
              


              <span class="error">[[+fi.error.myfield]]</span>
                  </label>
                  <input id="myfield" name="myfield:isEmptyOrNumber" type="text" value="[[+fi.myfield]]" />  
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 29266
                • 12 Posts
                sorry. my bad. all works great. Thanks!