<form class="{{class}} fade" action="{{ path }}" method="{{method}}" enctype="multipart/form-data">
{% for item in snippets %}
{% for form in item.form %}
{% for row in form.field %}
{{ include('pages/blocks/form/' ~ row.type ~ '.html.twig', {
content : row,
index : loop.index
}) }}
{% endfor %}
{% endfor %}
{% endfor %}
<input type="hidden" name="recaptchakey" value="6LfHlxIrAAAAAHU0zZg_LH6kRtAYpqWqv_gzVdsU">
<input id="recaptchaResponse" type="hidden" name="g-recaptcha-response"/>
<input type="hidden" name="referer" value="{{app.request.uri}}"/>
<input type="hidden" name="email-from" value="{{snippets ? snippets[0].submition_from : '' }}"/>
<input type="hidden" name="email-to" value="{{snippets ? snippets[0].submition_to : '' }}"/>
<input type="hidden" name="email-subject" value="{{snippets ? snippets[0].submition_subject : '' }}"/>
</form>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function() {
// Get the public key from the hidden input
var recaptchaKey = $('input[name="recaptchakey"]').val();
// Check if the key exists
if (recaptchaKey) {
// Load the reCAPTCHA API script dynamically
$.getScript('https://www.google.com/recaptcha/api.js?render=' + recaptchaKey, function() {
// Once the script is loaded, execute reCAPTCHA
grecaptcha.ready(function() {
grecaptcha.execute(recaptchaKey, {action: 'submit'}).then(function(token) {
// Set the token in the g-recaptcha-response input
$('#recaptchaResponse').val(token);
console.log('reCAPTCHA token generated and set successfully');
});
});
});
} else {
console.error('reCAPTCHA key not found');
}
});
</script>