User Submitted Event Spam
-
Our site accepts events submitted from users, but is getting spammed with fake event submissions. We’d like to be able to keep the submissions open to anonymous rather than logged in users only. Does anyone know how to add a ReCapthca form to the user submitted events page, or another method? Thanks.
-
You could try the method described here: https://ww.wp.xz.cn/support/topic/spam-protection-without-recaptcha-2/
They are basically adding a field at the end of the booking form asking the answer to the question “How much is three + five?” and then checking for the correct answer when validating the form.
My suggestion was for stopping spam on the booking form but you could do something similar for the front end event submission form.
function my_em_validate_anonymous_event_submission($result, $EM_Event) {
// Only apply validation if the user is not logged in (anonymous submission)
if (!is_user_logged_in()) {
if( empty($_REQUEST['control']) || "8" != $_REQUEST['control']){
$EM_Event->add_error( "Fill in the correct answer." );
$result = false;
}
}
return $result;
}
add_filter('em_event_save_pre', 'my_em_validate_anonymous_event_submission', 10, 2);
function my_control_html( $EM_Event ) {
?>
<p>
<label for='control'><?php _e('How much is three + five?','events-manager') ?></label>
<input type="text" name="control" id="control" class="input" value=""/>
</p>
<?php
}
add_action('em_front_event_form_footer', 'my_control_html', 8, 1);Thanks for updating for the event submissions. We are not having an issue with spam on bookings. Where would I add this code?
You can install the Code Snippets plugin and add the code there. Here are instructions on how to do it: https://docs.flycart.org/en/articles/2404915-using-code-snippets-plugin
Here’s a correction to the my_control_html function so the new field only appears when people are not logged in:
function my_control_html( $EM_Event ) {
if (!is_user_logged_in()) {
?>
<p>
<label for='control'><?php _e('How much is three + five?','events-manager') ?></label>
<input type="text" name="control" id="control" class="input" value=""/>
</p>
<?php
}
}-
This reply was modified 10 months ago by
joneiseman.
Thanks, but prefer to add without a plugin if possible. We are using a child theme. Would this go in functions.php?
Yes, it goes into the functions.php file in the child theme.
Great, appreciate your help.
@joneiseman I finally had a chance to implement the code you suggested. I do see the 3+5 question, but unfortunately it seems to cause a critical error when the user submits. Any suggestions? Here is the code to confirm I’m using correctly.
function my_em_validate_anonymous_event_submission($result, $EM_Event) {
// Only apply validation if the user is not logged in (anonymous submission)
if (!is_user_logged_in()) {
if( empty($_REQUEST['control']) || "8" != $_REQUEST['control']){
$EM_Event->add_error( "Fill in the correct answer." );
$result = false;
}
}
return $result;
}
add_filter('em_event_save_pre', 'my_em_validate_anonymous_event_submission', 10, 2);
function my_control_html( $EM_Event ) {
if (!is_user_logged_in()) {
?>
<p>
<label for='control'><?php _e('How much is three + five?','events-manager') ?></label>
<input type="text" name="control" id="control" class="input" value=""/>
</p>
<?php
}
}
add_action('em_front_event_form_footer', 'my_control_html', 8, 1);The filter name em_event_save_pre should have been em_event_validate.
Change line 11 from this:
add_filter('em_event_save_pre', 'my_em_validate_anonymous_event_submission', 10, 2);To this:
add_filter('em_event_validate', 'my_em_validate_anonymous_event_submission', 10, 2);Seems to be working. Thank you @joneiseman!
@joneiseman The code you provided is working in that it does require non-logged in users to solve the math equation to submit an anonymous event. However we are still receiving nearly the same amount of spam event submissions. Any ideas?
You could try a honeypot instead. The bots will fill in hidden fields so this code snippet will disallow the submission if the hidden field is filled in.
function my_em_validate_anonymous_event_submission($result, $EM_Event) {
// Only apply validation if the user is not logged in (anonymous submission )
if (!is_user_logged_in()) {
if( !empty($_REQUEST['control'])){
$result = false;
}
}
return $result;
}
add_filter('em_event_validate', 'my_em_validate_anonymous_event_submission', 10 , 2);
function my_control_html( $EM_Event ) {
if (!is_user_logged_in()) {
?>
<p>
<input type="text" name="control" id="control" class="input" value="" style ="display:none; visibility:hidden;"/>
</p>
<?php
}
} -
This reply was modified 10 months ago by
The topic ‘User Submitted Event Spam’ is closed to new replies.