hCaptcha
hCaptcha is the privacy friendly alternative to Google reCaptcha. Used by Cloudflare, Shopify & more..
Last updated
<form>
...
<! -- Step 1: Add this line -->
<div class="h-captcha" data-captcha="true"></div>
...
</form><! -- Step 2: Add the Web3Forms script -->
<script src="https://web3forms.com/client/script.js" async defer></script> <div class="h-captcha"
data-captcha="true"
data-lang="de"
data-theme="dark"
data-onload="myFunction"
data-render="explicit"
data-size="compact"
></div><script>
const form = document.getElementById('YOUR_FORM_ID');
form.addEventListener('submit', function(e) {
const hCaptcha = form.querySelector('textarea[name=h-captcha-response]').value;
if (!hCaptcha) {
e.preventDefault();
alert("Please fill out captcha field")
return
}
});
</script>// hCaptcha Site Key for Web3Forms
data-sitekey="50b2fe65-b00b-4b9e-ad62-3ba471098be2"<form action="https://api.web3forms.com/submit" method="POST">
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY_HERE">
<input type="text" name="name" required>
<input type="email" name="email" required>
<textarea name="message" required></textarea>
<! -- Step 1: Add this line -->
<div class="h-captcha" data-captcha="true"></div>
<button type="submit">Submit Form</button>
</form>
<! -- Step 2: Add the script -->
<script src="https://web3forms.com/client/script.js" async defer></script>npm install @hcaptcha/react-hcaptcha --save
# or
pnpm add @hcaptcha/react-hcaptchaimport { useForm } from "react-hook-form";
import HCaptcha from '@hcaptcha/react-hcaptcha';
export default function ContactForm() {
const { register, handleSubmit, setValue } = useForm();
const onHCaptchaChange = (token) => {
setValue("h-captcha-response", token);
};
const onSubmit = async (data) => {
console.log(data);
await fetch("https://api.web3forms.com/submit", {
method: "POST",
body: data
}).then((res) => res.json());
}
return (
<form onSubmit={handleSubmit(onSubmit)}>
{/* // other form fields */}
<HCaptcha
sitekey="50b2fe65-b00b-4b9e-ad62-3ba471098be2"
reCaptchaCompat={false}
onVerify={onHCaptchaChange}
/>
</form>
)}