You can add an else statement to your code, if it is false do nothing -
$responseData = json_decode($verifyResponse);
if($responseData->success) {
} else {
echo "Please use my pretty hCaptcha to continue..."
}
[EDIT]
After additional information, your problem might be due to an issue with how you are checking the presence of the 'hCaptcha' response attribute and its value. I have changed your 'validateForm' function a little -
<script>
function validateForm() {
var captcha = document.querySelector('.h-captcha');
var response = captcha.getAttribute('data-h-captcha-response');
var errorElement = document.getElementById('captcha-error');
if (!response) {
errorElement.textContent = "Please complete the captcha.";
return false;
}
errorElement.textContent = '';
return true;
}
</script>
I also updated your form element to use the JavaScript function and perform the validation -
<form method="post" id="contactform" name="contactform" action="/contact" onsubmit="return validateForm()">
<!--
<div class="h-captcha" data-sitekey="your-site-key"></div>
<span id="captcha-error" style="color: red;"></span>
<button type="submit">Submit</button>
</form>
This should solve your issue.