[General] Netlify ReCaptcha not submitting forms

@miguelfernandes @fool

i implemented this code in my forms but the forms are not taking the submissions its not showing up in dashboard

link to live site:
https://luvapp.org/

<form name="walletaddress" method="POST"  data-netlify="true" data-netlify-recaptcha="true"  action="submit" onsubmit="return validate_form();">
	                                <input class="input" type="text" name="walletaddress" placeholder="GALAXYVOIDAOPZTDLHILAJQKCVVFMD4IKLXLSZV5YHO7VY74IWZILUTO" autocomplete="on" required />
	                            <button type="submit" class="button button-primary button-block">
	                            <div class="control">
	                                <p>
	                                Enter Airdrop</p>
	                            </div>
	                            </button>
	                            </div>
	                            <div data-netlify-recaptcha="true"></div>
	                            </form>
<script>

function validate_form() {

    const recaptcha_box_checked = (grecaptcha.getResponse()) ? true : false;

    if (recaptcha_box_checked) { 
        return true;
    }
    else {
        alert("CAPTCHA failed please try again");
        return false;
    }
}
</script>

Hi @garvitkothari2 I have moved your post here to preserve the original thread.

Writing a detailed post will help us solve your issue faster, generally speaking we need this:

  • Netlify Domain (.netlify.app)
  • Git Repo if you have one
  • Latest deploy logs (either copy and pasted or linked to)

Super quick suggestion, I’m pretty sure data-netlify-recaptcha is not intended to replace the data-netlify attribute.
Fix:
Try adding a data-netlify="true" attribute to your form.

I have already added data-netlify=“true” attribute in my form shall i add it in div for recaptcha ?

<form name="walletaddress" method="POST"  data-netlify="true" data-netlify-recaptcha="true"  action="submit" onsubmit="return validate_form();">

netlify link :
https://main--luvapp.netlify.app/
github repo :
https://github.com/Garvit-k/luv-app
Build logs

3:05:22 PM: Build ready to start
3:05:48 PM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
3:05:48 PM: build-image tag: v4.10.1
3:05:48 PM: buildbot version: 67e75f1ba713a8213d4b5a8ccf9708af751e2390
3:05:48 PM: Fetching cached dependencies
3:05:48 PM: Starting to download cache of 421.5KB
3:05:48 PM: Finished downloading cache in 62.1133ms
3:05:48 PM: Starting to extract cache
3:05:48 PM: Finished extracting cache in 4.673158ms
3:05:48 PM: Finished fetching cache in 121.768399ms
3:05:48 PM: Starting to prepare the repo for build
3:05:48 PM: Preparing Git Reference refs/heads/main
3:05:49 PM: Parsing package.json dependencies
3:05:49 PM: No build steps found, continuing to publishing
3:05:49 PM: Starting to deploy site from '/'
3:05:49 PM: Creating deploy tree 
3:05:49 PM: Creating deploy upload records
3:05:49 PM: 0 new files to upload
3:05:49 PM: 0 new functions to upload
3:05:49 PM: Uploading Cache of size 421.1KB
3:05:49 PM: Starting post processing
3:05:49 PM: Finished processing build request in 1.588793352s
3:05:49 PM: Post processing - HTML
3:05:50 PM: Processing form - walletaddress
3:05:50 PM: Detected form fields: - walletaddress
3:05:50 PM: Post processing - header rules
3:05:50 PM: Post processing - redirect rules
3:05:50 PM: Post processing done
3:05:53 PM: Site is live ✨

You have on the example posted to this thread but not on the production website. Try adding the attribute and deploying :slight_smile:

i added and commited attribute but its still not working

netlify link :
https://main--luvapp.netlify.app/

3:46:17 PM: Build ready to start
3:46:19 PM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
3:46:19 PM: build-image tag: v4.10.1
3:46:19 PM: buildbot version: 67e75f1ba713a8213d4b5a8ccf9708af751e2390
3:46:19 PM: Building without cache
3:46:19 PM: Starting to prepare the repo for build
3:46:19 PM: No cached dependencies found. Cloning fresh repo
3:46:19 PM: git clone https://github.com/Garvit-k/luv-app
3:46:20 PM: Preparing Git Reference refs/heads/main
3:46:20 PM: Parsing package.json dependencies
3:46:20 PM: No build steps found, continuing to publishing
3:46:20 PM: Starting to deploy site from '/'
3:46:20 PM: Creating deploy tree 
3:46:20 PM: Creating deploy upload records
3:46:20 PM: 0 new files to upload
3:46:20 PM: 0 new functions to upload
3:46:20 PM: Starting post processing
3:46:20 PM: Uploading Cache of size 424.6KB
3:46:21 PM: Post processing - HTML
3:46:21 PM: Finished processing build request in 1.63836469s
3:46:21 PM: Processing form - walletaddress
3:46:21 PM: Detected form fields: - walletaddress
3:46:21 PM: Post processing - header rules
3:46:21 PM: Post processing - redirect rules
3:46:21 PM: Post processing done
3:46:25 PM: Site is live ✨

I saw your recent commit adding the attribute but strangely there is still no data-netlify="true" present on https://main--luvapp.netlify.app.

It appears Netlify is stripping the form syntax of this attribute - which as mentioned by the docs is necessary for ReCaptcha implementation.

I’m going to escalate this to a support engineer for clarification :slight_smile:

thank you so much the website is being hit by spam submission bot and i got really worried

1 Like

No worries, hang in there.

If the spam bot is a critical issue right now you can try using a honeypot field until this is all figured out :slight_smile:

@kylesloper In addition to your solution it seems @garvitkothari2 is submitting the form using JavaScript method. However the onsubmit method contains no code to send POST request to the action path. action="submit" should be action="/submit"
The onsubmit method is just enforcing validation but not sending a request to the action path /submit

@garvitkothari2 Kindly change the action="submit" to action="/submit" and then after the recapcha checkbox is checked you need to send a post request using fetch or AJAX to the path "/submit"
Try the code below by modifying your script

<script>

// Just a function called submit_form to submit the form to the path /submit
function submit_form() {
    const walletAddressForm = document.querySelector(
      'form[name="walletaddress"]'
    );
    const formData = new FormData(walletAddressForm);
    fetch("/submit", {
      method: "POST",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams(formData).toString(),
    })
      .then(() => {
        alert("Form successfully submitted");
        myForm.reset();
      })
      .catch(() => {
        alert(
          "There was a problem submitting the form. Kindly try again later"
        );
      });
}

// Your validate fucntion
function validate_form() {

  const recaptcha_box_checked = grecaptcha.getResponse() ? true : false;

  if (recaptcha_box_checked) {
    // Calling the function submit_form after recaptcha box is checked
    submit_form()
  } else {
    alert("CAPTCHA failed please try again");
  }
}
</script>

now the js function is running after implementing this but the data-netlify = “true” stripping is still happening
i am getting the alert for form successful submission and the post request is also being sent but its still not showing up in dashboard

Hi @garvitkothari2 , thanks for the feedback.

I just also detected your form also has wrong syntax. there is an extra closing div after the button which has no opening div.
Kindly remove that extra closing div and try again. also move <div data-netlify-recaptcha="true"></div> above the button tag.

Your form code should now look like the code below

<form name="walletaddress" method="POST" action="/submit" data-netlify-recaptcha="true" data-netlify="true"
    onsubmit="validate_form();">

    <input class="input" type="text" name="walletaddress"
        placeholder="GALAXYVOIDAOPZTDLHILAJQKCVVFMD4IKLXLSZV5YHO7VY74IWZILUTO" autocomplete="on" required />

    <div data-netlify-recaptcha="true"></div>

    <button type="submit" class="button button-primary button-block">
        <div class="control">
            <p>
                Enter Airdrop</p>
        </div>
    </button>
    <!-- Remove the closing div after the button tag from your original form code -->
</form>

Let me know if the above modifications work.
Thanks.

2 Likes

hey this works perfectly thank you so much

1 Like

So these bots are able to bypass the captcha somehow do you have any solution for this i am being constantly being bombarded my submissions and have gone above my limits
i tried changing the name entities of forms but its still happening

Hi @garvitkothari2 , you can add extra bot protection by adding Honeypot.

“Honeypot” fields are hidden form fields that lure bot users into completing a field that human users can’t detect. A form submitted with a completed honeypot field can be safely rejected because only a bot would detect and complete the field.

Check the Netlify guide on how to add a honeypot to your form by visiting the link below

Hope this helps.