This component will enable Friendly Captcha functionality on your form.
First, you need to set up some server side configuration via form builder. Read more about it here.
import {FriendlyCaptcha} from 'js-pimcore-formbuilder';
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.formbuilder.ajax-form').forEach((form) => {
new FriendlyCaptcha(form);
});
});
{
useAutoWidget: true,
autoWidgetVersionToLoad: null, // change to explict version you want to load from cdn: e.g. 0.9.16, null means latest
setupField: null,
friendlyCaptchaFieldClass: 'div.form-builder-friendly-captcha'
}
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.formbuilder.ajax-form').forEach((form) => {
new FriendlyCaptcha(form, {
useAutoWidget: false, // disable it to use your own implementation (see next option "setupField")
setupField: function (element, form, options) {
const friendlyCaptionOptions = {
doneCallback: function (solution) {
console.log("CAPTCHA completed successfully, solution:", solution);
},
sitekey: options.sitekey,
}
const widget = new WidgetInstance(element, friendlyCaptionOptions);
widget.start();
formBuilderForm.addEventListener('formbuilder.success', () => widget.reset());
formBuilderForm.addEventListener('formbuilder.error', () => widget.reset());
}
});
});
});