| Server IP : 121.121.20.254 / Your IP : 216.73.216.202 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/WPCAFE/wp-content/plugins/wp-cafe/base/validation/rules/ |
Upload File : |
<?php
namespace WpCafe\Validation\Rules;
/**
* Rule to ensure a field is present and not empty.
*/
class Required implements Validation_Rule_Interface {
/**
* Validate that the field is present and not empty.
*
* @param string $field The name of the field being validated.
* @param mixed $value The value to validate.
* @param array $all_data The complete set of data being validated.
* @return bool True if the value is not null or empty string, false otherwise.
*/
public function validate(string $field, $value, array $all_data): bool {
return !is_null($value) && $value !== '';
}
/**
* Get the error message for this rule.
*
* @param string $field The field name.
* @return string The error message.
*/
public function message(string $field): string {
return sprintf('The %s field is required.', $field);
}
}