-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.1] Form: Add regex validation rule #42657
Conversation
Hello Hannes, |
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. |
Co-authored-by: Brian Teeman <[email protected]>
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 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42657. |
What would be the right place to add the documentation before the PR is merged? |
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. |
@Fedik is that enough to justify this. Seems overkill to me to add this as its almost duplicate functionality |
Well, yes and no. |
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. |
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 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42657. |
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42657. |
I added documentation for all validation rules to the manual. Hope that is enough like this. |
Thx |
Summary of Changes
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 viavalidate_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.Testing Instructions
üüü
.validate="moduleLayout"
withOr it could be approved by maintainers by codereview.
Thanks
A big thanks goes to @coolcat-creations (Website) who sponsored this PR.
Link to documentations
Please select:
Documentation link for docs.joomla.org:
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org: Form: Serverside validation rules Manual#228
No documentation changes for manual.joomla.org needed