getgrav / grav-premium-issues

Official Grav Premium Issues repository to report problems or ask questions regarding the Premium products offered.
https://getgrav.org/premium
7 stars 2 forks source link

[typhoon] Captcha check always failing on Typhoon modular page #438

Open snakefox opened 4 months ago

snakefox commented 4 months ago

Hi,

I added the contact form to my modular Typhoon page and also enabled basic captcha as described here

The check is always failing even if the answer is correct and no mail is sent. There is no answer on that thread. Can someone please help ?

Thank you

rhukster commented 4 months ago

Make sure you have never_cache_twig: true in your modular page either the form.

snakefox commented 4 months ago

Hi,

I tried it but still the same. Here is my config:

modular page:

title: 'Secure Systems Design Lab'
content:
    items: self@.modular
onpage_menu: true
never_cache_twig: true
cache_enable: false

contact page:

body_classes: modular
cache_enable: false
never_cache_twig: true
form:
    name: contact
    action: '#contact'
    inline_errors: true
    fields:
        email:
            label: Email
            display_label: false
            placeholder: Mail
            type: email
            validate:
                required: true
        message:
            label: Message
            display_label: false
            placeholder: Nachricht
            type: textarea
            rows: 5
            minlength: 10
            maxlength: 255
            validate:
                required: true
        note:
            label: Hinweis
            display_label: false
            type: display
            size: large
            markdown: true
            classes: 'text-gray-600 dark:text-gray-400'
            content: '<center>Wir verwenden Ihre Angaben für die Bearbeitung von Anfragen. Unter <b><a href="https://cybermynd.io/de/datenschutz" target="_blank">Datenschutz</a></b> finden Sie weitere Informationen.</center>'
        basic-captcha:
            type: basic-captcha
            placeholder: Antwort
            display_label: false
    buttons:
        submit:
            type: submit
            classes: 'no-default-style text-white bg-primary hover:bg-red-800'
            value: Abschicken
    process:
        basic-captcha:
            message: 'Bitte nochmal versuchen..'
        email:
            from: '{{ config.plugins.email.from }}'
            to: '{{ config.plugins.email.to }}'
            subject: '[Kundenanfrage] cybermynd GmbH'
            body: '{% include ''forms/data.html.twig'' %}'
        message: '<b>Vielen Dank!</b> Wir melden uns zeitnah bei Ihnen.'
        reset: true
menu: Kontakt

I disabled all caching mechanisms on all levels as well.

rhukster commented 4 months ago

I can't really debug from 'inline' code.. you need to keep your newlines.. please insert code between triple backticks: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks

snakefox commented 4 months ago

Hi @rhukster,

sorry, I did not know how to do that but now it is fixed :- )

BR

snakefox commented 4 months ago

Hi @rhukster Do you have any updates ? It is very important to have a basic captcha in place to prevent from being overflooded by mails.

Thank you

rhukster commented 4 months ago

I don't see any issues with your form, if you remove the captcha: bit from your process, does the form submit correctly? Do you have a live site i can take a look at?

snakefox commented 4 months ago

Hi @rhukster,

you can find my live site here. Please scroll down to find the contact form.

Shall I change basic-captcha: to basic in process section ?

rhukster commented 4 months ago

process should definitely be basic-captcha:

I just tested a modular page (with cache enabled, even XHR enabled):

---
title: Modular Form B

form:
  name: Form B
  xhr_submit: true
  inline_errors: true
  fields:
    something:
      type: text
      label: Something Else
      validate:
        required: true
    basic-captcha:
      type: basic-captcha
      placeholder: copy the 6 characters
      label: Are you human?   

  buttons:
    submit:
      type: submit
      value: Submit

  process:
    basic-captcha:
      message: Humanity verification failed, please try again...
    message: "Thank you from your submission <b>{{ form.value('person.name') }}</b>!"
    reset: true
---

## XHR Modular Form

And it works 100% of the time as expected:

CleanShot 2024-06-04 at 13 10 58

snakefox commented 4 months ago

Hi @rhukster

still does not work for me. I switched to a honeypot instead to have some spam protection in place:

{% extends "forms/field.html.twig" %}

{% block field %}
{% set input_value = value is iterable ? value|join(',') : value|string %}
<input aria-hidden="true"
       type="text"
       {% if config.plugins.form.inline_css == true %}
       style="display:none;position:absolute!important;height:1px;width:1px;overflow:hidden;clip-path:inset(50%);"
       {% endif %}
       class="form-honeybear"
       name="{{ (scope ~ field.name)|fieldName }}"
       value="{{ input_value|e }}"
       tabindex="-1"
       autocomplete="off" />
{% endblock %}
rhukster commented 4 months ago

If you want, you can zip up your site and PM me how i can download it (on discord), then I can try to debug the issue you are having, because I currently can't replicate it.

snakefox commented 4 months ago

It is not required, thank you. I will come back if that kind of spam protection is not enough :- ) I just modified your honeypot.html.twig based on some articles I have found.