We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30319
    • 406 Posts
    Am I using an incorrect error placeholder??
    I have [[!+fi.error.math]] and Formit 2.0.3 installed on MODx 2.2-pl2 traditional.
    Entering a wrong math answer shows no error message, how to fix this??
    Thank you, Tom
      • 1778
      • 659 Posts
      Hard to answer if you don't show your code...
      Cheers
        • 30319
        • 406 Posts
        [[!FormIt?  
        &hooks=`email,redirect,math`  
        &emailTpl=`email`
        &emailSubject=`Website Inquiry` 
        &emailTo=`[email protected]`
        &emailCC=`[[+email]]`
        &emailFromName=`[[+name]]`
        &redirectTo=`27`
        ]]
        


        <p><label for="math">What is [[!+fi.op1]] [[!+fi.operator:is=`-`:then=`minus`:else=`plus`]] [[!+fi.op2]]?<span class="form-error">[[!+fi.error.math]]</span></label>
        <input type="hidden" name="op1" value="[[!+fi.op1]]" />
        <input type="hidden" name="op2" value="[[!+fi.op2]]" />
        <input type="hidden" name="operator" value="[[!+fi.operator]]" />
        <input type="text" name="math:required" value="[[!+fi.math]]" id="math" />
        <span class="help-inline">This ensures that you are a person, not an automated program, submitting this form. This field is required.</span>
        </p>
        
          • 1778
          • 659 Posts
          Hi,
          I believe you have to put the hook 'math' before the hook 'redirect', as Formit process them in the order you invoke them, the math hook is not fired since the redirect is fired before it (and redirect the user to your resource 27)
          Hope this helps
          Cheers
            • 30319
            • 406 Posts
            Unfortunately that does not fix it.
            The only error that does work is if the math field is blank which displays the 'this field is required' error message.
            I'll check the bugs site too...
            Thank you, Tom
              • 1778
              • 659 Posts
              Hi Tom,
              (May be it's a bit late to anwer) This behavior is normal...
              'math' is a hook (it's fired AFTER validation) and don't have fallback to return an error message on the form.
              If you want to display an error message if the answer is wrong you have to write a customValidator that will check if the input value is correct...

              Subtle difference between HOOKS and VALIDATORS... Validator check one or more conditions and returns on the form with error message since the condition(s) is right.
              HOOKS act only after validation, assuming your form has been submitted and all goes fine with the posted values... Then you can do any processing you want with these values...

              As the hook 'email' sends an email (and don't return error if it fails in this task) with the value you specify it does not check if the email is well formatted... To add to confusion there is also a built-in validator called email which is in charge of validation (check if the email is well formatted).


              Hope this helps
              Let me know if you have any problem
              Have swing
                • 30319
                • 406 Posts
                ahh...wrong answer validation is not built into the hook...thank you...
                any suggestions about custom validators for wrong answer??
                Thank you, Tom
                  • 1778
                  • 659 Posts
                  You have an example of custom validator called 'isBigEnough' in the rtfm: http://rtfm.modx.com/display/ADDON/FormIt.Validators in the paragraphs Built-in Validators (good to know what exists yet) et the next one Custom Validators...

                  With a validator $value is by default the value of the field you validate (math in your case)..
                  Have fun
                  Cheers

                  Sorry to not write a sample code for you but I'm facing a wall with Gallery since 3 days now and can't find any way to solve it ... Let me know if you need more help
                  Cheers
                    • 30319
                    • 406 Posts
                    This requires a separate forum thread, which I'll do now...
                    Thank you, Tom
                      • 50272
                      • 89 Posts
                      Hi Tom

                      I realise this thread has long since closed but I'm having the very same problem here now.
                      I've tried tracking down the new thread you mentioned you would start but without success.
                      Did you manage to remedy this in the end?
                      I do realise the passage of time may be an obstacle in itself
                      but many thanks anyway.

                      Regards
                      Chris