Eno\Field ยป error
error() โ ValidationError
error($message) โ ValidationError
error($message_function) โ ValidationError
Generate an error in the context of the element. The error includes a generic message by default, or a custom one if you supply it (which is the recommended practice). You can also pass a message function which (like the loader functions too) gets the name and value as arguments and returns a message string. This serves to create highly informative error messages that pin-point to the exact origin of the error, even when the initial reading of data is already past, e.g. when the error condition is only apparent later, when more processing has occurred or other data is available.
enocolor: cozy
php$document = Parser::parse($input);
$result = $document->field('color', [ 'with_element' => true ]);
// ...
if($result['value'] == 'cozy') {
throw $result['element']->error('Postprocessing determined that "cozy" is not a color after all.');
}
Parameters
$message or $message_functionHighly recommended to provide one (but it's optional).
Either directly pass a string, or alternatively a function returning a string.
(That function then gets $name
and $value
, in that order)
Return value
A ValidationError
in the context of the element's value(and with an optional custom message).