We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13428 ☆ A M B ☆
    • 1,031 Posts
    I have written a custom captcha and facing now the following problem:

    The captcha is called as preHook (because it has to display the captcha) and if not successfull the preHook is calling addError and returns with false. This error seems not to be mentioned later in the form process (i.e. by validate hook or FormIt itself), so the form is posted even with the error in preHook. Is that a bug or a feature?
      • 3186 ☆ A M B ☆
      • 279 Posts
      preHooks are not processed when you submit the form. So what I basically would do is set the captcha as normal HTML in your form and use a preHook to set the "code" to a session, add a postHook (eq. &hooks=``) to validate the submitted value against the session. And in there you should do $hook->addError() and the "return false;"

      Hope this helps smiley
        MODX Ambassador (NL) & Professional MODX developer
        Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
        MODX e-commerce solution SimpleCart
        • 13428 ☆ A M B ☆
        • 1,031 Posts
        Thanks for your answer. This was my first solution to solve that problem, too.

        But if i look in the code of firequest.class the function runPreHooks is called every time in request->prepare and just $fields is not set if the form is submitted. So if later in request->postProcess the function runPostHooks is called, the result of $this->formit->preHooks->hasErrors() could be retreived and $success = false could be triggered for this case too.

        So the snippet does not have to be called twice as pre and post hook. Maybe that would be accepted as pull request.