Jump to content

Simple anti-spam device


Perad

Recommended Posts

Hi, I am really struggling on this. All I am looking to do is have a simple question which visitors answer. I know this will not stop bots, its not supposed to. I am just looking for something which will stop the average user from posting without thinking.

 

This is what I have so far...

 

<script type="text/javascript">
num1 = Math.floor(Math.random()*25);
num2 = Math.floor(Math.random()*25);
function checkForm(submitted)
{
	if (num1 + num2 != submitted)
	{
		// Make element return error;
		return false;			
	}
}
</script>

<label for="anti-spam" id="anti-spam" style="float:left; padding-top:6px; margin-right:10px;">
<strong style="font-size:1.5em;">
	<script type="text/javascript">
		document.write(num1 + ' + ' + num2 + ' =');
	</script>
	<noscript>1 + 1</noscript>
</strong>
</label>

<input type="text" name="anti-spam" id="anti-spam" class="text" style="width:60px;" />
<span id="error"></span>

 

A couple of questions really.

 

1) Is there a way I can hide this form from people without Javascript?

2) How do make the error show up in the span tag with the id of error.

3) Where do I put this? Do I add the function to onSubmit="" at the top of the form.

 

Help is much appreciated.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/127371-simple-anti-spam-device/
Share on other sites

Just wanted to add, I have recently had a load of users posting one word replies in the comment box. Theory is.. if they have to add up 19+24 they won't bother posting.

 

Meanwhile if someone has something to say, doing the sum isn't a problem as the post contains enough value for it to be worth the effort. How effective it will be I will have to wait and see.

 

I know I could put a minimum length on posts but this stops people writing what they want.  I just want this :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.