Thoughts on QuickForm-additions
| From: | Stefan Neufeind | Date: | Wed, 13 Aug 2003 08:38:15 +0000 |
| Subject: | Thoughts on QuickForm-additions | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-19652@lists.php.net to get a copy of this message | ||
Just a quick note for the public (and maybe for discussion):
Been talking to Bertrand Mansion (one lead of HTML_QuickForm) I
proposed
a) addition of a new regex for validating numericals with up to two
decimals.
b) functions to validate a minValue and a maxValue for numerical
input fields.
In detail:
a) one example of such a regex allowing 0, 1 or 2 decimals would be:
/^(([0-9]+)|([0-9]+\.[0-9]{1,2}))$/)
The dot in this example could automatically be adjusted to fit the
locale setting of php, which might make it quite handy.
Bertrand responded to use registerRule during QuickForm-runtime to
register a new rule for this. That's something I intended to do for
the moment. But the basic idea was if numbers with up to two digits
are commonly used (e.g. for quantity or monetary values) and if such
a type might be a general enhancement so people don't need to find
that regex themselves, but can assume it just exists.
b) Currently there are minLength and maxLength refering to string-
length, which can easily be implemented via regex. This is however
not possible for minValue and maxValue refering to the numerical
value.
Bertrand pointed out correctly that it possible to write your own
function for server-side-validation of a numerical value and that if
you supply a JavaScript-function on your html-page with the same name
this function would also be used for client-side-validation.
I just thought having minValue and maxValue in QuickForm might be a
good idea so that people don't need to write 2 functions (server-side
and client-side) on their own, since I believe these value-bounds are
also commonly used. Another point that doesn't make comparing the
value entered in the form with a min/max-value that easy is that in
e.g. in Germany a comma is used as the decimal point. For validation
with JavaScript this would have to be converted to a dot before
comparisons. The same applies to server-side.
For the server-side validation Bertrand proposed to use the Validate-
package which, as he said, already handles locale settings for the
decimal separator.
So the question is whether people will implement such functionality
on their own every time they might need it or if these are such
elementary features that they should be added.
Your comments are very much appreciated. Please comment.
Stefan