Captcha in the Neos.Form-Builder

Hey ho,

has anyone of you experience with Captchas in the Neos.Form.Builder?
I miss the approaches how I should start and how to handle it.

Or is it better to make a simple JS/JQuery Solution?

I don’t want to use the recaptcha solution of google (it’s a instruction).

Hope anyone can help me.
Thank you very much :slight_smile:

Manu

That would defeat the purpose of a captcha which needs a server side to verify the reponse.
You can implement your own Form elements along the lines of:

class MyCaptchaFormElement extends AbstractFormElement
{

    /**
     * @param FormRuntime $formRuntime
     * @param mixed $elementValue
     * @throws InfiniteRedirectionException
     * @throws FormDefinitionConsistencyException
     */
    public function onSubmit(FormRuntime $formRuntime, &$elementValue)
    {
        if (empty($elementValue)) {
            return;
        }

        // use $this->getProperties() to get the form element's configuration
        
        // validate the $elementValue (e.g. by sending it to some 3rd party service)
        if (!$success) {
            $processingRule = $this->getRootForm()->getProcessingRule($this->getIdentifier());
            $processingRule->getProcessingMessages()->addError(new Error('Captcha failed. Please try again.', 12345678));
        }

    }
}

To make that work you need to configure the Form Element and set it’s implementationClassName option.
Take a look at existing custom Form Elements for inspiration.

1 Like

That would defeat the purpose of a captcha which needs a server side to verify the reponse.

Hm I thought so that, the JS Solution wouldn’t be such a good idea :sweat_smile:

Thank you very much, I will try it out.

What do you think about the “Honeypot” Solution? Could it be an alternative? I don’t know what I should think about that.