• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: PHP code to stop spam

PHP code to stop spam 12 years 4 months ago #20676

  • admin670
  • admin670's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
I have created a form with an anti-spam feature, I ask a question and check for the correct response that should be 'black'.

I have inserted the following PHP code in the "on form process" box:
if (isset($_POST) && strtolower($_POST) != 'black') die();

The form still ignores any value in the 'opposite' field.

Please advise.
The administrator has disabled public write access.

PHP code to stop spam 12 years 2 months ago #21701

Did you ever figure this out? I need this functionality too.
The administrator has disabled public write access.

PHP code to stop spam 12 years 2 months ago #21711

  • octavian
  • octavian's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 783
  • Thank you received: 110
Well, $_POST is actually an array that holds the submitted form data. RSForm! Pro's values are stored inside $_POST, followed by the name of the fields (for example, if you have a textbox named "Answer", your value will be stored inside $_POST).
So, basically, you add the following script Properties > PHP Scripts > Scripts called on form process:
$myfield = 'Answer';
$myanswer = 'black';
// no need to edit below
if ($_POST['form'][$myfield] != $myanswer) {
	$invalid[] = RSFormProHelper::getComponentId($myfield);
}

The same effect could be achieved without any custom scripting, by adding a textbox field, setting the "Default Value" to "black" or whatever the correct answer is, clicking on the "Validations" tab and setting "Validation Rule" to "Passphrase (set it in Default Value)".
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.
The following user(s) said Thank You: adam.blakesley

PHP code to stop spam 12 years 2 months ago #21726

Thanks so much octavian. That script works like a charm. I couldn't get the alternative method to work but I'm sure that was due to my own ineptitude.
The administrator has disabled public write access.

PHP code to stop spam 12 years 1 month ago #22331

  • alexc
  • alexc's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 11
Thank you octavian. The PHP script worked perfect.

This method below just so anyone knows does not
The same effect could be achieved without any custom scripting, by adding a textbox field, setting the "Default Value" to "black" or whatever the correct answer is, clicking on the "Validations" tab and setting "Validation Rule" to "Passphrase (set it in Default Value)".

Because the answer is actually populated in the field itself which completely defeats the purpose
Last Edit: 12 years 1 month ago by alexc.
The administrator has disabled public write access.

PHP code to stop spam 12 years 1 month ago #22335

  • octavian
  • octavian's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 783
  • Thank you received: 110
The method above has been tested by me and it works correctly. Please make sure you are using the latest version of RSForm! Pro.
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!