Skip to content

Commit f1d3af8

Browse files
authored
Merge pull request #44 from netgen/Document-invisible-captcha
Document invisible captcha
2 parents c02caab + 9971eb6 commit f1d3af8

1 file changed

Lines changed: 51 additions & 5 deletions

File tree

doc/CAPTCHA.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Example template implementation for `ng_feedback_form` would be something like t
117117
{{ form_end(form) }}
118118
119119
120-
{% if info_collection_captcha_is_enabled(location) %}
120+
{% if info_collection_captcha_is_enabled(location.innerLocation) %}
121121
<div class="info-collector-captcha">
122122
<script src='https://www.google.com/recaptcha/api.js'></script>
123123
{% set captcha = info_collection_captcha_get_site_key(location) %}
@@ -160,7 +160,7 @@ Or, using captcha v3:
160160
{{ form_end(form) }}
161161
162162
163-
{% if info_collection_captcha_is_enabled(location) %}
163+
{% if info_collection_captcha_is_enabled(location.innerLocation) %}
164164
{% set captcha = info_collection_captcha_get_site_key(location.innerLocation) %}
165165
<div class="info-collector-captcha">
166166
<script src="https://www.google.com/recaptcha/api.js?render={{ captcha }}"></script>
@@ -182,6 +182,52 @@ Or, using captcha v3:
182182
{% endblock %}
183183
```
184184

185-
If captcha validation results in error with code "missing-input-response" you probably did not send reCAPTCHA token in variable "g-recaptcha-response".
186-
Another error you might encounter is "action-mismatch". In this case make sure that the action you specified in captcha config (globally or per content type)
187-
is the same as the one you use when executing captcha check.
185+
Or, using invisible captcha:
186+
```twig
187+
{% block content %}
188+
<div class="view-type view-type-{{ view_type }} ng-feedback-form">
189+
<div class="full-form-content">
190+
{% if not is_valid %}
191+
{% if not content.fields.body.empty %}
192+
{{ ng_render_field(content.fields.body) }}
193+
{% endif %}
194+
195+
{{ form_start(form, { 'attr': { 'id': 'ng_feedback_form'} } ) }}) }}
196+
{{ form_errors(form) }}
197+
198+
<fieldset>
199+
{{ form_row(form.sender_name, {attr: {class: 'form-control'}}) }}
200+
{{ form_row(form.email, {attr: {class: 'form-control'}}) }}
201+
{{ form_row(form.subject, {attr: {class: 'form-control'}}) }}
202+
{{ form_row(form.message, {attr: {class: 'form-control'}}) }}
203+
204+
<input name="g-recaptcha-response" hidden>
205+
<button type="submit" class="btn btn-primary g-recaptcha" data-sitekey={{info_collection_captcha_get_site_key(location.innerLocation)}} data-callback='onSubmit'>Send</button>
206+
</fieldset>
207+
208+
{{ form_rest(form) }}
209+
{{ form_end(form) }}
210+
211+
212+
{% if info_collection_captcha_is_enabled(location.innerLocation) %}
213+
<div class="info-collector-captcha">
214+
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
215+
<script>
216+
function onSubmit(token) {
217+
document.getElementById("ng_feedback_form").submit();
218+
}
219+
</script>
220+
</div>
221+
{% endif %}
222+
223+
{% else %}
224+
{{ block('success') }}
225+
{% endif %}
226+
</div>
227+
</div>
228+
{% endblock %}
229+
```
230+
231+
If captcha validation results in error with code `missing-input-response` you probably did not send reCAPTCHA token in variable `g-recaptcha-response`.
232+
Another error you might encounter is `action-mismatch`. In this case make sure that the action you specified in captcha config (globally or per content type)
233+
is the same as the one you use when executing captcha check.

0 commit comments

Comments
 (0)