Use the frm_spam_entry_sources filter to add your own spam check to the checks that can save a submission as a spam entry. Each check in the list gets its own row in the spam check settings.
In that row, a site admin chooses whether submissions your check flags are saved as spam entries or rejected. Your own code still decides when a submission is spam.
Upgrade your WordPress site with powerful, flexible forms.
Requirements
- Formidable Forms 7.0 or later. The hook is part of Formidable Forms Lite.
From Idea to Reality in Minutes. Build Powerful Forms, Dashboards, Apps and More.
Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.
How it works
The filter adds your check under Formidable → Global Settings → Captcha/Spam → Spam checks, in the Customize how spam submissions are handled section. Its dropdown offers Save as a spam entry and Reject with an error message. Learn more about spam checks.
Your code runs the check, usually in the frm_validate_entry filter. When a submission fails it, call FrmSpamEntriesHelper::maybe_flag_submission():
- It returns
truewhen your check is set to save. The submission is saved as a spam entry. The visitor sees the normal success message. - It returns
falsewhen your check is set to reject, or when spam entries can't be saved on the site. Add an error so the submission is rejected.
Only new submissions can be saved as spam entries. When an entry is being edited, reject it instead.
In the Spam tab of the entries list, the entry's spam reason shows your label and the reason you passed, such as "Disposable email address: mailinator.com".
Usage
add_filter( 'frm_spam_entry_sources', 'my_function_name' );Parameters
- $sources (array): The spam checks, keyed by a unique source key such as
honeypotorakismet. Each check is an array with a label and a default. - $sources[ $key ]['label'] (string): The check's name in the settings and in the spam reason.
- $sources[ $key ]['default'] (string):
saveto save flagged submissions as spam entries, orblockto reject them. It applies until a site admin saves a different choice.
FrmSpamEntriesHelper::maybe_flag_submission() parameters
- $form_id (int): The ID of the submitted form.
- $source (string): The source key of your check.
- $reason (string, optional): Details shown after the label in the spam reason.
Examples
Save submissions from disposable email addresses as spam
This example adds a "Disposable email address" check. It flags new submissions whose email address uses one of the listed domains. Replace 25 with the ID of your Email field. Then list the domains you want to catch.
add_filter( 'frm_spam_entry_sources', 'my_frm_add_spam_source' );
function my_frm_add_spam_source( $sources ) {
$sources['disposable_email'] = array(
'label' => 'Disposable email address',
'default' => 'save',
);
return $sources;
}
add_filter( 'frm_validate_entry', 'my_frm_check_disposable_email', 20, 2 );
function my_frm_check_disposable_email( $errors, $values ) {
if ( $errors ) {
return $errors; // The submission already has errors.
}
$field_id = 25; // Change 25 to the ID of your Email field.
$email = isset( $values['item_meta'][ $field_id ] ) ? strtolower( trim( (string) $values['item_meta'][ $field_id ] ) ) : '';
$domain = false !== strpos( $email, '@' ) ? substr( strrchr( $email, '@' ), 1 ) : '';
$blocked = array( 'mailinator.com', 'yopmail.com' );
if ( ! in_array( $domain, $blocked, true ) ) {
return $errors;
}
$is_new = empty( $values['id'] ) && 'update' !== ( $values['frm_action'] ?? '' );
if ( ! $is_new || ! FrmSpamEntriesHelper::maybe_flag_submission( $values['form_id'], 'disposable_email', $domain ) ) {
$errors['spam'] = 'Please use a different email address.';
}
return $errors;
}
Limitations
- The filter adds the setting and the spam reason label. The check itself runs only where your code calls FrmSpamEntriesHelper::maybe_flag_submission().
- Flagging a submission while an entry is being edited has no effect. The example rejects edits that fail the check instead.
Related developer hooks
- Decide whether a flagged submission is saved or rejected with the frm_save_spam_entry hook.
- Add your own validation to a submission with the frm_validate_entry hook.
- Turn off Honeypot on one or all forms with the frm_run_honeypot hook.