Recaptcha is functioning properly on smartphones, however, it is experiencing difficulty on computers

Hey there! I encountered an issue with my website where the recaptcha isn't working on the desktop version. It's strange because I've used the same code successfully on other sites before.

I attempted to fix it by creating a new recaptcha and testing it in different browsers, but to no avail.

Some users suggested that I might be loading the recaptcha twice, but after checking my files, I can't seem to find any duplicates other than the google api link in the header.

The header:

<script src='https://www.google.com/recaptcha/api.js' async defer></script>
</head>

My contact form's recaptcha section looks like this:

<div class = "row d-none d-sm-none d-md-block">
   <div class = "col-md-6">
      <div class="g-recaptcha" id = "captcha" name = "captcha" data-sitekey="SITE_KEY_HERE" style = "text-align:left;"></div>
   </div>
   <div class = "col-md-6">
      <div class = "submit" style = "text-align: right;">
         <button id = "submitForm" type="submit" name = "submit" class="btn btn-lg">Send Message</button>
      </div>
   </div>
</div>
<div class = "row d-inline-block d-sm-inline-block d-md-none">
   <div class = "col-sm-12 text-center">
      <div class="g-recaptcha" id = "captcha" name = "captcha" data-sitekey="SITE_KEY_HERE" style = "text-align:center;"></div>
   </div>
</div>
<div class = "row d-block d-sm-block d-md-none">
   <div class = "col-sm-12 text-center">
      <div class = "submit">
         <button id = "submitForm" type="submit" name = "submit" class="btn btn-lg">Send Message</button>
      </div>
   </div>
</div>

Upon the expected appearance of the 'I am not a robot' checkbox, I encountered the following error on the desktop version:

ERROR for site owner: Invalid domain for site key

Interestingly, the mobile version works flawlessly.

Even after assigning unique recaptcha keys for the desktop and mobile versions, the issue remains unresolved.

Answer №1

Hooray, I figured it out!!

Apologies to all for the confusion.

It turns out that I had inadvertently included two versions of the contact form without realizing it. I was unintentionally neglecting to update the site key for the form visible on desktop, instead editing the version that I believed to be the only one. As a result, the form kept appearing as invalid.

I sincerely apologize for the oversight. This serves as a reminder that sometimes meticulously reviewing your code can save you from such issues.

Answer №2

In the event that the desktop is reloading twice, it may indicate a problem with the code below.

class = "row d-inline-block d-sm-inline-block d-md-none"

Could you switch the class to "visible-xs" and test if that resolves the issue?

Answer №3

Have you attempted the specific rendering method discussed in this article - https://developers.google.com/recaptcha/docs/display#explicit_render

As outlined in the provided link, update your script tag to

<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
    async defer>
</script>

Then create a callback function to dynamically render the desired widget (maybe based on screen size!) similar to the example below.

<script type="text/javascript">
      var onloadCallback = function() {
        if (screen.width < 600)
            grecaptcha.render('captcha-one', { //id of the first captcha needs to be captcha-one
              'sitekey' : 'your_site_key'
            });
        else
            grecaptcha.render('captcha-two', { //id of the second captcha needs to be captcha-two
              'sitekey' : 'your_site_key'
            });
      };
    </script>

Alternatively, you could render both of them based on the provided examples in the mentioned link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust font size using jQuery

Hey there! I have a small question. I want to resize all HTML elements using jQuery, but the current code allows me to increase and decrease the size infinitely. var originalSize = $('html').css('font-size'); // Reset ...

Struggling with loading external scripts within background.js in Chrome extensions?

I am facing an issue with my chrome extension. I am unable to call an external script, specifically the ethereum script (web3.min.js), from within my background.js file. The error message I receive is: Uncaught EvalError: Refused to evaluate a string ...

Quick method to assign child iframe title as index.html <title>title</title>

Is there a simple method to dynamically update the <title> of my index.html based on the <title> of a child iframe? Take a look at my website for reference If the content within the iframe changes, will the title automatically update along wi ...

`Back and forward function of pushState in history`

After successfully implementing ajax loading on all pages of my website, I encountered a challenge with the browser's back and forward buttons. Implementing the back button was straightforward: $(window).on('popstate', function(e) { get ...

Oops! There was a validation error as the duration was not formatted as a number. Please make sure to provide a valid numerical value for the duration field

When attempting to update data from a MongoDB database and checking the results on Postman, an error is encountered. The error reads as follows: "Error: ValidationError: duration: Cast to Number failed for value \"NaN\" at path \"duration&bs ...

Why can't we use percentages to change the max-height property in JavaScript?

I am currently working on creating a responsive menu featuring a hamburger icon. My goal is to have the menu list slide in and out without using jQuery, but instead relying purely on JavaScript. HTML : <div id="animation"> </div> <button ...

Can we specify the inherit value for font family on an element to ensure consistent style when the specified font is not available?

Suppose I have a page with the following HTML content: <body style="font-family:Helvetica"> <span style="font-family:Segue">Hello World</span> </body> Would it be considered valid to set the font family of the span to Segue, ...

"Enhance your webpage with a captivating opaque background image using Bootstrap

I'm new to exploring Bootstrap and I am currently experimenting with options for displaying content with a semi-transparent background image. Currently, I am using a "well" but I am open to other suggestions. I have managed to place the image inside t ...

Including HTML attributes within a PHP script

Currently, I am working on developing a message to be displayed to the user after they have submitted the contact form using PHP. However, I am facing an issue with styling the message as intended, particularly with elements like bold text and line breaks ...

Ensure that the input field requires the first letter to be capitalized and the subsequent letters to be in lowercase

There are numerous ways to capitalize the first letter and make the rest lowercase on Stack Overflow. However, I am looking for a method that can instantly enforce this rule in the input field. Being new to AngularJS, I am currently working with version 1 ...

Retrieve the route.js directory using Node.js

My server.js file is located in the directory: /dir1. To start the server, I use the command node server.js. In the directory /dir1/app/, I have my file named routes.js. I am trying to find out the directory path of the server.js file. However, I am unc ...

What is the best way to show the selected values of dropdown and checkboxes on a redirected page for confirmation using PHP?

<form action="action.php" method="POST" target="_self"> <table class="main" border="1" height="100%" align="center">t; <h3> <p id="id1" style="background-color: #9FF" >Registration form</p></h3> <tr><t ...

Error not caught: AngularJS module error

Initially, I was hesitant to ask this question, but after struggling for two hours without any success, I've decided to seek some assistance. I'm trying to integrate the ngResource module into my application. Prior to this, everything was functi ...

Issue with jQuery validation plugin is that the select element is not being properly validated

The jQuery validation plugin I'm using (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) is functioning properly on most elements, but there are 2 select boxes where it's not working. You can see an example of one of these problema ...

The global variable remains unchanged after the Ajax request is made

I am attempting to utilize AJAX in JavaScript to retrieve two values, use them for calculations globally, and then display the final result. Below are my code snippets. // My calculation functions will be implemented here var value1 = 0; var v ...

Why is it necessary to use "new" with a Mongoose model in TypeScript?

I'm a bit confused here, but let me try to explain. When creating a new mongoose.model, I do it like this: let MyModel = moongoose.model<IMyModel>("myModel", MyModelSchema); What exactly is the difference between MyModel and let newModel = ne ...

How come the font size doesn't transfer from the div element to the table element?

I am experiencing an issue with my document presentation. The document is simple and includes HTML and CSS code as well as some text content. When I render the document, I notice that the table element does not inherit the font size from its parent div, un ...

Utilizing jQuery to dynamically calculate real-time output from user input in a form

My task involves creating a form where the user fills out certain values, and I want to display a calculated value based on those inputs at the bottom of the form. Unfortunately, I'm not seeing any output at all. Here is the HTML form I have attempte ...

Guide to incorporating dynamic components into Angular Router

I am currently working on developing a pluggable Angular application. During my research, I came across the following insightful article: Building an extensible Dynamic Pluggable Enterprise Application with Angular Everything was going smoothly until I ...

Checkbox enabled Bootstrap image

I am encountering a minor issue where I am attempting to incorporate a simple image that can be toggled on and off by clicking on it. After coming across some bootstrap code online, I decided to test it in my project. Unfortunately, the code does not seem ...