Skip to content

Commit b1fbf31

Browse files
authored
Merge pull request #37 from bvrbanec/improvement/captcha-docs
Added docs for reCAPTCHA v3
2 parents 8751b36 + 5a87322 commit b1fbf31

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

doc/CAPTCHA.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,56 @@ Example template implementation for `ng_feedback_form` would be something like t
132132
</div>
133133
{% endblock %}
134134
```
135+
136+
Or, using captcha v3:
137+
```twig
138+
{% block content %}
139+
<div class="view-type view-type-{{ view_type }} ng-feedback-form">
140+
<div class="full-form-content">
141+
{% if not is_valid %}
142+
{% if not content.fields.body.empty %}
143+
{{ ng_render_field(content.fields.body) }}
144+
{% endif %}
145+
146+
{{ form_start(form) }}
147+
{{ form_errors(form) }}
148+
149+
<fieldset>
150+
{{ form_row(form.sender_name, {attr: {class: 'form-control'}}) }}
151+
{{ form_row(form.email, {attr: {class: 'form-control'}}) }}
152+
{{ form_row(form.subject, {attr: {class: 'form-control'}}) }}
153+
{{ form_row(form.message, {attr: {class: 'form-control'}}) }}
154+
155+
<input name="g-recaptcha-response" hidden>
156+
<button type="submit" class="btn btn-primary">Send</button>
157+
</fieldset>
158+
159+
{{ form_rest(form) }}
160+
{{ form_end(form) }}
161+
162+
163+
{% if info_collection_captcha_is_enabled(location) %}
164+
{% set captcha = info_collection_captcha_get_site_key(location.innerLocation) %}
165+
<div class="info-collector-captcha">
166+
<script src="https://www.google.com/recaptcha/api.js?render={{ captcha }}"></script>
167+
<script>
168+
grecaptcha.ready(function () {
169+
grecaptcha.execute('{{ captcha }}', {action: 'feedback'}).then(function (token) {
170+
$('[name="g-recaptcha-response"]').val(token);
171+
});
172+
});
173+
</script>
174+
</div>
175+
{% endif %}
176+
177+
{% else %}
178+
{{ block('success') }}
179+
{% endif %}
180+
</div>
181+
</div>
182+
{% endblock %}
183+
```
184+
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 (globaly or per content type)
187+
is the same as the one you use when executing captcha check.

0 commit comments

Comments
 (0)