简体   繁体   中英

How to make email submit form hide “form action=bla-bla.php” part from bots?

I have bot/fake emails being submitted to my email list every day even though they don't show up in my landing page google analytics statistics where my email submit form is. I was told that the bots are bypassing the form probably, sending POST requests straight to the URL where the form is submitted.

<form action="http://example.com/something.php">

They go straight to something.php and submit.

I was told that I could either make a javascript that submits the form onclick (so the form doesn't show the action stuff) or through some modifications to the PHP script that is processing the form.

I have no idea how to do that. Can you help me?

The original bare bones form code:

<form action="https://app.getresponse.com/add_subscriber.html" accept-charset="utf-8" method="post" class="w3-container w3-card-4 w3-light-grey w3-text-blue w3-margin">

  <input class="w3-input w3-border" name="email" input type="email" required placeholder="Enter Your Email Here">
  <input type="hidden" name="campaign_token" value="fhdfh" />
  <input type="hidden" name="thankyou_url" value="https://example.com/confirm-email.php"/>
  <input type="hidden" name="start_day" value="0" />
</div>

<div style="margin-top:25px;"><button type="submit" class="w3-button w3-block w3-section w3-deep-orange w3-ripple" style="padding-top:15px;padding-bottom:15px;">Send me the eBook on Email</button></div>

</form>

The best way to prevent this would be to implement some sort of validation like reCAPTCHA: https://developers.google.com/recaptcha/

A very simple first step could be to set the action in a JavaScript snippet. Most of these bots do not execute javascript and will try to post to the page the form is on (probably not very future proof, but it has been working since 2005 for me)

In the code below, I have added an id to the form tag, removed the action attribute and added a bit of javascript to set it after page load.

 <form id="myform" accept-charset="utf-8" method="post" class="w3-container w3-card-4 w3-light-grey w3-text-blue w3-margin"> <input class="w3-input w3-border" name="email" input type="email" required placeholder="Enter Your Email Here"> <input type="hidden" name="campaign_token" value="fhdfh" /> <input type="hidden" name="thankyou_url" value="https://example.com/confirm-email.php" /> <input type="hidden" name="start_day" value="0" /> <div style="margin-top:25px;"><button type="submit" class="w3-button w3-block w3-section w3-deep-orange w3-ripple" style="padding-top:15px;padding-bottom:15px;">Send me the eBook on Email</button></div> </form> <script> document.getElementById('myform').setAttribute('action', 'https://app.getresponse.com/add_subscriber.html'); </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM