Refactor form validation #360
No reviewers
Labels
No labels
Component: User interface
Component: Wymeditor
Help wanted
Level: Difficult
Level: Easy
Level: Moderate
Pagetype: Festival
Pagetype: Mailinglist
Pagetype: Peer reviewed article
Pagetype: Text
Privacy GDPR AVG
status: has conflicts
Status: Needs changes
Status: Needs discussion
Status: Needs review
Status: Ready to merge
Status: Waiting for response
Type: Bug
Type: Enhancement
Type: Question
Usecase: De Stadsbron
Usecase: Koppelting
Usecase: MeetjeStad
Value: Coders
Value: Security
Value: Users
Value: Visitors
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
harmen/hypha!360
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refactor-form-validation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The main point of this PR is the last commit, which guards against insertion of
<script>tags in HTML fields. The other commits refactor the form input validation so there is now a singlevalidate()method that must always be called, where this check can be done automatically on all wymeditor fields (previously, validation always required callingvalidateXXXField()methods explicitly). These refactors were something I had been considering for a while, since they make the form generation again a little bit more declarative and automatic.@ -591,0 +661,4 @@function validateHtmlField($name) {$value = $this->dataFor($name);if (!$value)return true;If an email field is empty I think you would like the message 'required field missing', not 'incorrect email address' which seems to happen now that the first error gets overwritten by the second? Perhaps shift the order? Or make the errors per name into an array instead?
I find this message slightly confusing..
If I as a user would copy paste some html I wanted to use and I get a notification that my computer might be infected by a virus. I would get worried, perhaps for the wrong reasons.
Something along these lines perhaps?
"HTML <script> tags are not allowed. They are considered unsafe as they can be used for hacks or virusses."Does this need to be cleaned up afterwards?
Ah, just read this comment in the code above, this explains the reasoning behind the stringent message. But I think the message could still be made more clear.
@ -591,0 +661,4 @@function validateHtmlField($name) {$value = $this->dataFor($name);if (!$value)return true;Ah, no because the an empty email field is considered valid, the error won't be overwritten.
@ -591,0 +661,4 @@function validateHtmlField($name) {$value = $this->dataFor($name);if (!$value)return true;Exactly.
@ -584,2 +639,4 @@* directly.*/function validateEmailField($name) {$value = $this->dataFor($name);Executing the form validate() here, if not yet done, would reduce some code duplication. It would loose it's const-ness but it would perform more as the name suggests.
Yeah, I didn't spend too much effort on the message, since it should not normally be shown. Do you have a specific suggestion for a better message?
I don't think so, since it is created but not added into the document tree (so I'm assuming PHP will garbage collect the DomNode itself).
@ -584,2 +639,4 @@* directly.*/function validateEmailField($name) {$value = $this->dataFor($name);Interesting idea, though I'm not entirely sure. Always running validate would mean a form can be validated more than once (which is a waste of efffort), but running it only if not ran before means that re-validating after a change in the form is not possible (we don't really use or support this now, though).
But maybe running it when not ran before is a good idea. If we ever need to re-validate, you could just call
validate()explicitly then. I'll see how to best implement this, since it might nicest to fold this change back into the git history (but maybe that's too much work and I'll just add a new commit).Something like this?
"HTML
@ -584,2 +639,4 @@* directly.*/function validateEmailField($name) {$value = $this->dataFor($name);If it would self validate, then, when a value gets updated, the is_validated flag could be set to false.
Very cool improvement!
Thanks, I've used your suggestion.
@ -584,2 +639,4 @@* directly.*/function validateEmailField($name) {$value = $this->dataFor($name);Ok, I implemented automatic validation like suggested. Re-validating / clearing
is_validatedon changes is not yet implemented, since there is no meaningful way to change values right now I believe, so this is left for later.Rebased on top of master and made some small changes based on review, going to review next.
Hm, turns out this has an unintended side effect: Because everything lives in one big form, validation errors in e.g. the comment form let the browser prevent submitting the login form.
For now, I've fixed this by reverting this PR on www.destadsbron.nl, but the proper fix for this is probably to separate each form into its own
<form>tag, which is a refactor that we were planning to do anyway (which is #359).