User tests: Successful: Unsuccessful:
This PR adds a regex validation rule for the Form library. The base class for Form validation rules has validation with regular expression implemented, but no way to hand in a regular expression via the form definition. You have to build your own validation rule class, register it in Joomla and can then use it. That seems overly complex for this, so this PR adds a rule to add regular expression validation.
For your field, you add validate="regex"
to your form definition and the regular expression via validate_regex=""
. The value of the field is then validated server side against the regex given. You have to pay attention that you might have to escape the regex properly when adding it to the validate_regex attribute. You can also add a modifier at the end.
üüü
.validate="moduleLayout"
with
validate="regex"
validate_regex="^([A-Za-z0-9_-]+:)?[A-Za-z0-9-][A-Za-z0-9\.-]*$"
Or it could be approved by maintainers by codereview.
A big thanks goes to @coolcat-creations (Website) who sponsored this PR.
Please select:
Documentation link for docs.joomla.org:
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org: joomla/Manual#228
No documentation changes for manual.joomla.org needed
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Thanks @webnet-assmann. Yes, that would be a successfull test. The goal was to show that the regex validation rule properly functions, regardless if we use the specific rule for moduleLayout or if we copy the regex from there into the XML.
Labels |
Added:
Feature
PR-5.1-dev
|
Tested successfully
Tested successfully
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42657.
@webnet-assmann Could you mark your test result in the issue tracker so it’s properly counted? Just go to https://issues.joomla.org/tracker/joomla-cms/42657 , use the blue „Test this“ button at the top left corner, then select your t st result and submit. Thanks in advance.
This really needs sopme documentation please
I have tested this item ✅ successfully on 70a3a53
Tested successfully
What would be the right place to add the documentation before the PR is merged?
but no way to hand in a regular expression via the form definition.
Is that really correct? You can use html5 pattern already and from what I can see it does the same thing and is something we already use. What does this offer that is different?
For example:
@coolcat-creations All of that is already possible using pattern (https://www.html5pattern.com/) or am I missing some big difference that requires this extra code
@brianteeman html5 attribute "pattern" is client side, what is in PR is server side.
It is probably possible to use the same pattern for both client and server (and so simplify the field set up), but I did not tested such thing, cannot say for sure.
Seems overkill to me to add this as its almost duplicate functionality
Well, yes and no.
You know, you cannot rely on client side validation, never.
agree when it is security related such as with a password but in these examples client side is much faster and provides a better user experience
@brianteeman I'm happy to discuss improvements on the client side in the future, but we need server side validation and this is such a server side validation. If you want to get rid of duplicate functionality, we could rather talk about removing the validation rules we have right now which only contain such a regex. However, there are good reasons for providing even such basic rules like Boleean or ModuleLayout.
agree when it is security related such as with a password but in these examples client side is much faster and provides a better user experience
We basically need both. Server side is always going to be required regardless (if nothing else we have an API still to maintain which can't do HTML5 validation). Many of the security issues we had in 3.9/3.10 were people intercepting requests from forms to the server and then making further modifications because we weren't doing proper server side validation (only client side). For regex things it's hard to say what the business implications might be - but I'm sure there's going to be some business cases things like phone numbers might be required.
TLDR: I think this is fine - combining the server and client side regex together into a single field if provided definitely a nice to have though.
I have tested this item ✅ successfully on 70a3a53
Status | Pending | ⇒ | Ready to Commit |
RTC
Labels |
Added:
RTC
Documentation Required
|
I added documentation for all validation rules to the manual. Hope that is enough like this.
Labels |
Removed:
Documentation Required
|
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-02-28 17:43:21 |
Closed_By | ⇒ | bembelimen |
Thx
Hello Hannes,
I've tested it, but I don't know if I understood it correctly:
You have to select something in the Advanced tab under Layout and enter a value with mutated vowel. I can't change the values there, so I created another file for Layout with üüü and then selected that. Then I got the error message. Then I changed the corresponding code in the mod_custom.xml file and selected üüü again and the error message appeared again, but the other values could be saved.
If I have understood correctly, then the test was successful.