Our site is successfully checking form entries and sending some to spam. Currently it’s testing whether the last two text entry fields have identical content. I’d like to add a test on whether more than two checkboxes are selected in our “What can we help you with?” field. Spam bots seem to be almost universally checking all boxes.
Can anyone help fill in the necessary if code?
Here’s the currently working code. (Inserted with WPCode.)
I need to get an integer of how many checkboxes are checked in ‘input_5’ and if greater than two, tag the entry with $is_spam. I think this would be in a second if block since I want either test to work independently of the other.
I’ve been reading around the internet and GF docs for hours and don’t feel like I’m any closer to knowing how to do it. The Checkboxes Field section of https://docs.gravityforms.com/entry-object/ probably has something to do with it but again, I don’t know how.
That works! Those checkboxes are a required field on the form so I took out your parts that checked if they were empty. The form had 500 entries in 2024, 99% spam. This will capture almost 98% of the spam. If you think it would be useful, consider adding your code as an example on the page for gform_entry_is_spam. On forms that didn’t have a bunch of checkboxes, this might work as a manual honeypot approach on hidden checkboxes.
Thanks!
My snippet as deployed with your additions:
// My spam check, edited to compare fields 4 and 5. PLUS CHECKBOXES code suggested by Richard W., simplified
add_filter( 'gform_entry_is_spam_1', 'duplicate_field_values_and_checkboxes', 11, 3 );
function duplicate_field_values_and_checkboxes( $is_spam, $form, $entry ) {
if ( $is_spam ) {
return $is_spam;
}
$next_last_field = rgar( $entry, '4' );
$last_field = rgar( $entry, '7' );
if ( ! empty( $next_last_field ) && ! empty( $last_field ) && $next_last_field === $last_field ) {
return true;
}
// Look at ID 5, the checkboxes, count, spam if > 2
$field_5 = GFAPI::get_field( $form, 5 );
$field_5_inputs = $field_5->get_entry_inputs();
$field_5_checked_count = 0;
foreach ( $field_5_inputs as $input ) {
$value = rgar( $entry, (string) $input['id'] );
if ( ! rgblank( $value ) ) {
$field_5_checked_count ++;
}
}
if ( $field_5_checked_count > 2 ) {
return true;
}
return false;
}