contao/core — pull request #4129 by Toflar (2012-03-29 14:35:55+00:00)
Title: Regex validation

Hi Leo

The first commit is a proposal of how we could allow to display more than one error message per field in the DCA. The current behaviour is a bit strange:

1. Enter invalid data that produces 2 or more errors (I don't know if that's even possible in the core)
2. Fix the error you are notified about (but you only know about one, because only one message gets displayed)
3. Send the form again -> it will again tell you that the value is incorrect which is a bit tedious ;)

The first commit fixes this and provides the number of errors and a popup view for all the details if you click on the message :)

In fact this is a product of my attempt to allow more than one regular expression on a field. I tried but I couldn't really come up with a good solution as the current implementation is really inflexible.
There are a lot of

if ($arrData['eval']['rgxp'] == 'date')

comparisons in the code and I think a lot of extensions use this too. So I thought about the problem again and I think that the real problem is that if we want to use an existing rgxp, we have to copy the whole code and so I ended up creating a new class called "Validator" that contains all the methods to check for different things.
This way one can easily reuse and combine different methods in his own rgxp which is still not perfect but a huge improvement already. A proper implementation where the validation goes into the Model can be considered for Contao Reloaded.

The code as is does not properly work, because in the Validator class I need to call methods (idnaEncode etc.) that are currently not static yet. So in fact you'd need to make all the methods static that do not need the object context. But that was a goal of Contao 3 anyway and some of it has already been done by Andreas (https://github.com/contao/core/pull/3898) :)

Thx for implementing and improving!