macder / wfv-validation Goto Github PK
View Code? Open in Web Editor NEWInput validation API for WordPress
Home Page: https://macder.github.io/wfv/
License: BSD 3-Clause "New" or "Revised" License
Input validation API for WordPress
Home Page: https://macder.github.io/wfv/
License: BSD 3-Clause "New" or "Revised" License
albeit this goes against my philosophy of 'do not return rendered markup,' it will make templates cleaner.
idea is to have an option to avoid doing:
<input type="hidden" name="action" value="<?php echo $contact_form->get('action'); ?>">
<?php echo $contact_form->get('nonce_field'); ?>
and instead:
<?php echo $contact_form->action_token(); ?>
this does not render anything, just returns the encoded string: $form->input()->render('name')
more semantically correct would be $form->input()->escape('name');
The automation needs to be strategic
Should become more clear as more units get complete
new structure should look like:
array(
'email' => [
'label' => 'Email',
'rules' => 'required|email',
'messages' => [
'required' => 'Custom required validation error msg',
'email' => 'No email? No soup for you!',
],
'phone' => [
//...
]
]
);
error()
method on WFV_Form
achieve behaviour similar to the input()
shorthand
In order to repopulate checkboxes or multiselects, i.e. select them after validation fail - keep user sane...
Create a helper method to return a 'checked' or 'selected' attribute for checkbox and multiselect fields
Currently, custom rules can only be simple callbacks that don't take in any additional parameters
There are cases when parameters are necessary
It is doing more than 1 thing. Split the logic into simple pure functions to make it more readable and testable
Certain parts of FormComposite have been refactored. Good opportunity to create new tests instead of trying to adapt the old ones
Should be able to take in the input as JSON and return a validation result JSON
API has standardized - make unit tests for all simple and pure methods
build an api that returns a forms configuration as JSON
making it compatible with https://validatejs.org/ might be good start
Currently the FormComposite holds an array of validation strategies (ValidateInterface) and loops through them during validation. This is somewhat confusing, making it unclear that a strategy pattern is being used. It also add's too much responsibility to the FormComposite.
The new Validator class will be added to the FormComposite as a class member, and the FormComposite will feed it a single strategy at a time.
The only validation responsibility the FormComposite should have is providing correct strategies to the Validator
stripcslashes()
should solve this
Valitron uses a God class, so only way to add new rules is either with callback or extending the Valitron class. Both approaches would get messy fast, therefore this library needs to be replaced.
Respect\Validation is more flexible. Can create a validator class for each rule and then use a strategy pattern to validate input.
This opens the door to creating an unlimited amount of built in rules by just adding new validator classes.
For instance, if a ruleset for a field is defined like so ['required', ['lengthMin', 3] ]
the entire system grinds to a halt.
Must add support for rules that are arrays
This is a meaty one...
Now that most methods and properties are known, create decorator class or classes
provide a better alternative to $form->input()->render('name')
A builder pattern to build the form instance is more appropriate and extendable, especially since the form class take 4 instance params to construct
Create a method to check if a field has an error, return true or false
Will be useful for adding error classes in markup
The Validator class is doing things that are not directly related to getting a validation result. Many of the methods are more appropriate for the Form Class.
The inheritance should become unnecessary after this rework, making the class hierarchy flat
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.