# give/4.16.9/src/Framework/FieldsAPI/Concerns/IsRequired.php

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

- Page: https://pluginprobe.com/plugins/give/4.16.9/code/src/Framework/FieldsAPI/Concerns/IsRequired.php
- Raw: https://pluginprobe.com/plugins/give/4.16.9/raw/src/Framework/FieldsAPI/Concerns/IsRequired.php
- Modified: 2025-09-17T16:52:40+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/Framework/FieldsAPI/Concerns/IsRequired.php#L10-L20`.

```php
<?php

namespace Give\Framework\FieldsAPI\Concerns;

trait IsRequired
{
    /**
     * Marks the field as required or not.
     *
     * @since 2.24.0 switch to new validation system
     */
    public function required($value = true): self
    {
        if ( $value ) {
            $this->validationRules->rules('required');
        } else {
            $this->validationRules->removeRuleWithId('required');
        }

        return $this;
    }

    /**
     * Returns whether the field is required or not.
     *
     * @since 2.24.0 switch to new validation system
     */
    public function isRequired(): bool
    {
        return $this->hasRule('required');
    }

    /**
     * @deprecated Use the Validator to generate errors
     */
    public function getRequiredError(): array
    {
        return [
            'error_id' => $this->name,
            'error_message' => __('Please enter a value for ', 'give') . $this->name,
        ];
    }
}

```
