# give/4.16.9/src/DonationForms/Rules/HoneyPotRule.php

GiveWP – Donation Plugin and Fundraising Platform, version 4.16.9. 46 lines.

- Page: https://pluginprobe.com/plugins/give/4.16.9/code/src/DonationForms/Rules/HoneyPotRule.php
- Raw: https://pluginprobe.com/plugins/give/4.16.9/raw/src/DonationForms/Rules/HoneyPotRule.php
- Modified: 2024-09-25T21:57:00+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.16.9/code/src/DonationForms/Rules/HoneyPotRule.php#L10-L20`.

```php
<?php
namespace Give\DonationForms\Rules;

use Closure;
use Give\DonationSpam\Exceptions\SpamDonationException;
use Give\Log\Log;
use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule;

/**
 * @since 3.16.2
 */
class HoneyPotRule implements ValidationRule
{

    /**
     * @since 3.16.2
     */
    public static function id(): string
    {
        return 'honeypot';
    }

    /**
     * @since 3.16.2
     */
    public static function fromString(string $options = null): ValidationRule
    {
        return new self();
    }

    /**
    * @since 3.16.2
     * @throws SpamDonationException
     */
    public function __invoke($value, Closure $fail, string $key, array $values)
    {
        if (!empty($value)) {
            Log::spam('Spam donation detected via Honeypot field.', [
                'formId' => $values['formId'] ?? null,
            ]);

            throw new SpamDonationException(__('Thank you for the submission!', 'give'));
        }
    }
}

```
