-3

I am a newbie to programming and I already struggled a lot for a week to have a fully functional form that validates, stores data, and then redirects.

Please let me know about a captcha that is easy to install and doesn't mess up my code resulting in data not being sent to PHP which javascript did to me.

F. Müller
  • 3,969
  • 8
  • 38
  • 49

4 Answers4

2

A very cheap way of doing a quick and dirty check could be something like this:

<form name="form" method="post">
  <!-- your other form fields -->
  <input type="text" id="title" name="title" value="somethingsomething">
  <input type="submit" value="send">
</form>

You can make the field invisible and choose a name, that a bot would definitely fill out. Choose anything meaningful just not something like "antispam" or the like.

input#title {
  visibility: hidden;
  height: 0;
  width: 0;
} 

And then just check if the input field got set:

<?php

if (isset($_POST["title"])) {
  // a bot had filled the field now, do something
}

?>

The concept is called "honeypot". You can also check out this stackoverflow post here:

Better Honeypot Implementation (Form Anti-Spam)

F. Müller
  • 3,969
  • 8
  • 38
  • 49
  • Sounds interesting , can you also suggest me what function should be there if it's a bot ? – Sensitive music Aug 14 '20 at 06:00
  • @Sensitivemusic Well you probably don't want the bot to spam so you can just block his IP (won't work if he is hiding it though) or you could just say "technical issues try later". There is no right way. If you want a good solution pick a library from a professional provider instead. If this is for a school project or the like you can go with this simple stuff. But obviously you don't want to send the form. I have added a link to another post - he does it with checkboxes which might be even better. – F. Müller Aug 14 '20 at 06:32
0

You can use the google cpatcha. You do not have to code at all

Procedure

1.Log on to your Google account.

2.Access https://www.google.com/recaptcha/adminInformation published on non-SAP site from your browser.

3.Select the Invisible reCAPTCHA radio button.

4.Register your domain.

Remember
Your domain is the URL of your Identity Authentication tenant. It has the <tenant ID>.accounts.ondemand.com pattern.

Tenant ID is automatically generated by the system. The first administrator created for the tenant receives an activation e-mail with a URL in it. This URL contains the tenant ID.

5.Save your Site key and your Secret key. You need them for the configuration steps in the administration console for Identity Authentication.

Source of answer

Jerry
  • 366
  • 4
  • 22
  • That's complicated , since I m a newbie I m sure Its gonna mess up my code resulting in data not being sent to php , or user not being redirected to url , is there anything easier ? – Sensitive music Aug 14 '20 at 05:34
0

[Try this

  • The best CAPTCHA codes
  • No CAPTCHA reCAPTCHA
  • Image CAPTCHA
  • add a CAPTCHA to your website

][1] document :- url [1]: https://internet.com/website-building/how-to-add-a-captcha-to-your-website/

0

Try this:

  1. Register an hcaptcha account and follow it's instructions.
  2. Add <script src="https://hcaptcha.com/1/api.js" async defer></script> to your head if you have not already done so
  3. Add <div class="h-captcha" id="captcha" data-sitekey="INSERT SITEKEY HERE" data-theme="dark"></div> (Leave data-theme="dark" in for dark theme).
  4. In your form tag, add onsubmit="return checkCaptcha()" as an attribute, like so: <form onsubmit="return checkCaptcha()">
  5. Add the function below to your JS code:
function checkCaptcha() {
    if (hcaptcha.getResponse() == "") {
          return false;
    } else {
          return true;  
    }
}
Duncan Leung
  • 142
  • 1
  • 11