I need to rearrange conditions to hide the reCaptcha response in the front end, as shown in the image below:
I have the following function:
function my_contact_form_generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='alert alert-primary' role='alert'>{$message}</div>";
else $response = "<div class='alert alert-danger' role='alert'>{$message}</div>";
}
reCaptcha response
$request = "https://www.google.com/recaptcha/api/siteverify?secret={$secretkey}&response={$recaptchaResponse}&remoteip={$userIp}";
$content = file_get_contents($request);
$json = json_decode($content);
Conditionals are:
if ($json->success == "true") {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
my_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
my_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, strip_tags($admin_email), $headers);
if($sent){
my_contact_form_generate_response("success", $message_sent); //message sent!
$_POST = array();
}
else {
my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
}
}
}
} else {
my_contact_form_generate_response("error", $recap_invalid);
}
How can I re-arrange my conditions to hide the failed ReCaptcha error message and only display it if it fails after submitting the form?
Thank you in advance.