Created
June 9, 2022 09:19
-
-
Save rvalitov/00a628b1bb51307e18ee9649412343f9 to your computer and use it in GitHub Desktop.
RSForm PHP script to silently reject submission from spammers based on their email address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This script is used to silently reject submissions from spammers if you know their email addresses that they | |
* put into your contact form. | |
* This script checks if the user's email in the submitted form exists in your configured blacklist of email addresses. | |
* The comparison is done case-insensitive. | |
* If match is found, then such submission is rejected. | |
* Rejected submissions are not saved into the database of RSForm and all notification emails are not sent. | |
* After the rejected submission received, the user will be redirected to the same contact page | |
* (or another page if you configure that) with a configurable message. | |
* Usually such message should be a fake successfully received submission notification, so it does not look | |
* suspicious to the spammer. | |
* Tested with Joomla 3.10.9, RSForm 3.0.18, PHP 7.4. | |
* | |
* How to use: | |
* 1) go to your form -> Form Properties -> PHP Scripts -> Script called on form process. | |
* 2) put the code below into the "Script called on form process" textarea. | |
* 3) change the configuration of the code according to our form. | |
*/ | |
/** | |
* Start of configuration, change the values below according to your form and needs | |
*/ | |
//The field in RSForm for the email field | |
$fieldName = 'contact-email'; | |
//List of user emails that are blacklisted and such submissions will be rejected, one per line | |
$blacklist = [ | |
'[email protected]', | |
'[email protected]', | |
]; | |
//Fake message to the user that the form has been submitted: | |
$fakeMessage = 'Thank you! Your form has been submitted'; | |
//Redirect URL, usually you don't need to change that: | |
$redirectUrl = JRoute::_('index.php'); | |
/** | |
* End of configuration, please, don't change the code below | |
*/ | |
$app = JFactory::getApplication(); | |
if (isset($_POST['form'][$fieldName]) && in_array(mb_strtolower(trim($_POST['form'][$fieldName])), $blacklist)) { | |
$app->enqueueMessage($fakeMessage); | |
$app->redirect($redirectUrl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment