I have a form where I have to fill in some information. For one of the fields of the form, I need to create a custom validator. In fact, I need to valdiate that the entered string is in a specific format like ab.123.cd
I am able to validate this by using regexp, but the "ab" should be eqal to another field of my form, so I need to access this other field in my validator class.
Here is my validator:
public function validate($value, Constraint $constraint)
{
preg_match('/[^\/]+/i', $value, $publisherDoiAbbr);
if($publisherDoiAbbr[0] !== $enquiry->getPublisher()->getDoiAbbreviation()) {
$this->context->addViolation($constraint->message_publisher_DOI);
}
$this->context->addViolation($constraint->message_journal_DOI);
}
I need here the $enquiry->getPublisher()->getDoiAbbreviation()
Do you know how can I access the values of my form in the validator class?
Thank you in advance.