Jump to content

What's wrong with this condition check using a form submission?


R0CKY

Recommended Posts

I have a script installed that has a comment form that I want to protect from spam with a simple math question.

 

I added a new field into the form called antispam, and in the form processor page I added a check for the answer to be correct. I can't get it to work though.

 

By a process of trial and error though I discovered I can get a condition check to work if I use one of the existing fields. For example if I change the condition check to only proceed if the subject field is "PASS", then it will work. But as soon as I try and use the new antispam field, it does not work, whether the answer is correct or wrong, it still pasts the comment. This confuses me.

 

Here's the code I am using. I have commented in <!-- ANTI SPAM ROW --> to show the only 4 lines of code I inserted into this form.

 

The form

 

	<form action="{$settings.dburl}/index.php?act=comments&c=post&file={$file.file_id}" method="post">
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="0" class="border">
  <tr class="sectionheader">
	<td width="100%" colspan="2">
	  {#post_comment#}		</td>
  </tr>
  <tr>
	<td width="50%">{#poster#}:</td>
        <td width="50%"><input type="text" name="subject" id="subject" size="40" maxlength="150" /></td>
  </tr>
  <tr>
	<td align="center" colspan="2">
	  <textarea name="comment" id="comment" rows="12" style="width: 95%"></textarea>		</td>
  </tr>
<!-- ANTI SPAM ROW -->
      <tr>
      <td width="50%">Anti Spam : What is 2 + 2?</td>
      <td width="50%"><input type="text" name="antispam" id="antispam" size="1" maxlength="1" /></td>
      </tr>
      <tr>
	<td align="center" colspan="2">
	  <input type="submit" value="{#post_comment#}" onclick="postComment({$file.file_id}); return false;" /><br />
	  <div id="status" style="font-weight: bold"></div>		</td>
  </tr>
</table>
</form>

 

 

The Form Processor

 

In this page I added a simple check

 

if ($_POST['antispam'] == "4") $enableComments = true;

 

This does not work though. However if I was (just for testing purposes) to do a check on the subject field (as follows) it works!

 

if ($_POST['subject'] == "SPAM") $enableComments = false;

 

So I have figured out the problem is with the new antispam field I added - but what is the problem?

 

Many thanks for any advice on this one.

 

 

Yeh I tried that but I don't see the echo anywhere, the page refreshes really quick, the comment appears posted and there is no echo in sight. I think I need to try and stop the code somewhere (somehow) so I get time to see the echo.

 

I just know that it won't display the spam field, but you are right we need to see, I'm going to dig a bit deeper.

It's getting to confusing for me as a php n00b to follow, I found that there are apparently two form processors in this downloads system, one called ajax.php and one called ajax.js  :-\

 

I think I am going to have to give up on this and find another way to stop the spammers.

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.