Drupal is a registered trademark of Dries Buytaert

Makes fields conditionally required based on other field values. Works with all entity types (nodes, users, taxonomy, custom entities). User-friendly configuration form with dropdown selects. Supports CKEditor, image, file, and all field types.

Features

Basic Functionality

The Required If Field Has Value module allows site administrators to configure conditional field requirements. Instead of making a field always required, you can make it required only when another field has a value. This provides flexible validation rules that adapt to user input.

Unique Features

  • Universal Entity Support: Works with all fieldable entity types in Drupal, including Content (nodes), Users, Taxonomy terms, Custom entities, and any entity type that supports fields.
  • Intelligent Field Detection: Properly handles complex field types including text fields with CKEditor (strips HTML to detect actual content), image and file fields (detects uploaded files correctly), entity reference fields, link fields, and all standard field types.
  • User-Friendly Configuration: Intuitive form with dropdown selects (no need to remember field machine names), visual table interface for managing multiple rules, responsive design that works on mobile devices, and AJAX-powered field dependencies that update automatically.
  • Robust Architecture: Service-based design for extensibility, automatic migration from previous versions, clear error messages with field labels, and validates rule configuration to prevent errors.

When and Why to Use This Module

Use this module when you need conditional field requirements that aren't possible with Drupal's standard field settings. Common scenarios include:

  • Contact Forms: Make phone number required only if email is provided
  • User Profiles: Require job title only when company name is filled
  • Product Forms: Make warranty information required only if warranty is selected
  • Event Registration: Require dietary restrictions only if attending the dinner
  • Content Creation: Make related fields required based on content type selections

Use Cases

  • E-commerce: Require shipping address only when physical product is selected
  • Forms: Make optional fields required based on user selections
  • User Registration: Conditional profile fields based on user type
  • Content Management: Require related metadata when specific content is added
  • Multi-step Forms: Ensure data consistency across conditional sections

Post-Installation

Configuration Process

  1. Enable the Module: Navigate to /admin/modules, find "Required If Field Has Value" under the "Fields" package, and enable the module.
  2. Configure Rules: Go to Configuration > System > Required If Field Has Value (/admin/config/content/required-if-filled), and click "Add another rule" to create a new conditional requirement.
  3. Set Up Each Rule:
    • Entity Type: Select the entity type (Content, User, Taxonomy Term, etc.)
    • Bundle: Choose the specific bundle (Article, Page, User, etc.)
    • Source Field: Select the field that, when filled, triggers the requirement
    • Required Field: Choose the field that becomes required when the source field has a value
  4. Save Configuration: Click "Save configuration" to apply your rules.

How It Works

Once configured, the module automatically:

  • Adds validation to entity forms matching your rules
  • Checks if the source field has a value when the form is submitted
  • Validates that the required field also has a value
  • Displays clear error messages if validation fails

Special Considerations

  • Field Requirements: The module only works with fields that are not already marked as required in field settings. Fields that are always required cannot be used as "required fields" in rules.
  • Cache: Clear Drupal cache after configuration changes if rules don't appear to work immediately.
  • Migration: If upgrading from version 1.0.x, rules are automatically migrated to the new format. No manual intervention needed.

Additional Requirements

Core Requirements

  • Drupal 10 or Drupal 11
  • PHP 8.1 or higher

Dependencies

This module has no external dependencies beyond Drupal core. It uses only core APIs and services.

While not required, these modules can enhance your experience:

  • Field Group: Organize fields into collapsible groups for better UX
  • Webform: Use with Webform entities for conditional requirements in webforms
  • Conditional Fields: For more complex conditional field visibility (complements this module)
  • Field Permissions: Control who can edit fields, works well with conditional requirements

Similar projects

Conditional Fields

  • Difference: Conditional Fields controls field visibility based on other fields. This module controls field requirements (validation). They complement each other and can be used together.

Field Validation

  • Difference: Field Validation provides general validation rules. This module specifically focuses on conditional required validation with a simpler, more intuitive interface.

Webform Conditional

  • Difference: Webform Conditional is specific to Webform entities. This module works with all entity types and their standard forms.

Why Choose This Module?

  • Simplicity: Easy-to-use interface with dropdown selects
  • Universal: Works with all entity types, not just specific ones
  • Reliable: Properly handles complex field types like CKEditor and images
  • Maintained: Active development following Drupal best practices

Supporting this Module

This module is open source and maintained by the community. You can support its development by:

  • Reporting Issues: Help improve the module by reporting bugs on the issue queue
  • Contributing Code: Submit patches and improvements
  • Documentation: Help improve documentation and examples
  • Testing: Test new releases and provide feedback
  • Rating: Rate the module on its project page

Your contributions help make this module better for everyone!

Community Documentation

Official Resources

  • Project Page: See the main project page for downloads and information
  • Issue Queue: Report bugs and request features
  • Documentation: See the README.md file included with the module

Getting Help

  • Support: Post questions in the issue queue
  • Bug Reports: Use the issue queue with detailed information
  • Feature Requests: Suggest new features via the issue queue

Contributing

Contributions are welcome! Areas where help is needed:

  • Additional field type support
  • Performance improvements
  • Documentation examples
  • Translation (i18n) support

Additional Information

  • Performance: The module is lightweight and adds minimal overhead. Validation only runs on form submission for entities matching configured rules.
  • Security: The module follows Drupal security best practices, uses Drupal's form API and validation system, respects entity access permissions, and uses Drupal's configuration system.
  • Accessibility: The configuration form is fully accessible with keyboard navigation support, screen reader compatibility, responsive design for all devices, and clear labels and error messages.

Version History

  • Version 1.1.0 (Current): Added support for all entity types, improved configuration form with dropdown selects, enhanced field value detection for CKEditor and image fields, added responsive design, improved code architecture with services, and automatic migration from version 1.0.x.
  • Version 1.0.x: Initial release with basic conditional required field validation, node entity support only, and textarea-based configuration.

Activity

Total releases
4
First release
Dec 2025
Latest release
1 month ago
Release cadence
15 days
Stability
75% stable

Release Timeline

Releases

Version Type Release date
1.2.1 Stable Jan 30, 2026
1.2.0 Stable Jan 26, 2026
1.1.0 Stable Dec 16, 2025
1.0.x-dev Dev Dec 15, 2025