forms
forms copied to clipboard
Container: added params to addEmail()
added missing params $cols + $maxLength in addEmail() method
What is $cols useful for?
Hi,
parameter $cols is very, very important, because emails can be in length up to 245 characters and if html attribute size ($cols) is missing, browsers render by default email input for approx 20 characters. Many users may experience that their email address will not fit into this 20 characters input and part of it will be hidden. If you set for example $cols = 50, $maxLength = 250, 99% of all email addresses will perfectly fit.
The parameter $cols + $maxlength are already used in Container::addText() method so using parameters with the same name in addEmail() is more than logical.
Another point is relatively confusing naming of the html attribute size like $cols, but the constraint isn´t $maxCols, but $maxLength. Moreover cols html attribute is used in textarea, where $cols isnt the same as $length, because $length = $cols x $rows. The best naming of parameters would be $length + $maxLength (for all text single line inputs) but from php 8.0 might be BC problems with named parameters. That's why I proposed name of the parameter $cols like in addText().
emails can be in length up to 245 characters
How did you come up with this number?
Path is defined as "<" [ A-d-l ":" ] Mailbox ">
(https://www.rfc-editor.org/rfc/rfc5321#section-4.1.2)
Path size maximum is 256 octets. (https://www.rfc-editor.org/rfc/rfc5321#section-4.5.3.1.3)
Octets, not characters, so size would be determined by strlen(), not mb_strlen().
Subtracting required characters <>
(internally used), usable length of email is 254 octets.
That's the only maximum size, that makes sense. Any lower number would reject otherwise perfectly fine email.
if html attribute size ($cols) is missing, browsers render by default email input for approx 20 characters
Why would you use size instead of css? Use all available space for input, it's probably not gonna be more than 254 characters
the figure 245 characters I have found somewhere on internet. Important is the default size of email input approx. 20 characters. Many email addresses have more characters than 20 - this is the main point. For example my email address [email protected] has approx. 22 characters and would have small problem to fit in 20 characters.
CSS sizing is possible but use html attribute size ($cols) is also good way.
I would like to get rid of $cols
parameters, this belongs to CSS, it doesn't work for type=number
, the unit is strange (each letter is differently wide). So I really don't want to add it to another method unless there's an extra good reason.
In the case of $maxLength
, it would probably be practical to use a default value of 254 in there, if emails really can't be longer.
- I'am using $cols, simple way how to define length for each individual input, it doesn't belong to css, arguments:
a. $length ($cols) + $maxLength depend on database meta data + business analyse, not on graphic design. Lets take sample of email, we have one figure 254 characters defined by internet standards, another numer 40 - maxLength of email in real life (99% of all emails) - so best solution is set $cols = 40 + $maxength = 254. These settings make the email input be functionable for all possible emails up to the theoretical maximum + 99% all real emails will be fully displayed. This is function not graphic.
b. For example I use css for forms with several text inputs in that way that $cols in all inputs define the width (depending on db) and the form container only respects by css .form-container { width: fit-content} this is easy, simple, flexible and perfectly working solution
c. If somebody decide define width of text input by css and not use parameter $cols he can, this parameter should be optional
-
default value of $maxLength - OK but I recommend to do a precise inspection of the real max value and this we can put there
-
input type=number is not text based input but number based, $cols (better $length) should be used for single-line-text inputs (Text, Email, Password, ...)
-
I also want to turn the attention to the consistency and clarity of names of parameters (as of PHP 8.0 important part of public API) and i recommend change the name od $cols to $length - in all single-line-text inputs, arguments:
- $length + $maxLength this makes sense, $cols + $maxLength is highly misleading
- single line inputs do not contain columns, they contain strings and strings in all languages have length as number of chars
- only in case textarea we should use $cols
-
another related point with just opened idea of $maxLength default value is to connect $maxLength with corresponding validation rule - automatically - working on browser and also on server, but this idea is out of topic of this PR, so I prepare a corresponding complex proposal for enhancement based on this idea
It's not $length, it's $width. And it's not very clear in what units the width is.
The name of the html attribute for input type=text is size:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text#size
Define text input width with css ?
Think about the real world. Forms are usually created in two steps first create database table + corresponding form, second create css for the form. These steps are often done with separate people, define width od input by css has that consequence that frontendman should scan database structure to get maxlength number for every text input and write database dependent css for every column. Change in database results in need of change css.
The unit is unclear and we cannot rely on it ?
Yes, but this is merely theoretical problem. In the real world the things goes like this: You establish text input for surname maxlength 40 characters, but size only 30 characters. How many people really have more than 30 characters in surname ?? 0,01% ?? OK 0,01% experience that small part of surname will scroll. And if there is difference in units and the real size will be not 30, but 31 or 29 - this still makes no troubles.
Change name of the $cols parameter ??
Yes, html attribute cols has only textarea, using $cols for inputs is from PHP >= 8.0 not good idea. OK lets rename the parameter from $cols to $size according to the html standard - and do it for all single line text inputs.
Optional parameters with default value ??
For PHP >= 8.0 is no problem - people can use names of parameters
BC breaks
Unfortunately change of the name of the parameter is BC break, but I don' t expect many people really use name of parameter $cols now. But the name of the parameter is now a part of public api, so that´s why I recommend to change the misleading name $cols now, later would be more difficult.
What do you thing ?
In a typical form, each input is not a different width because it would look ugly. They only have two or three kind of sizes, which are mainly defined by classes or layout.
Survey https://twitter.com/geekovo/status/1648380363029331973?s=61&t=YigoQdwYMQ7gxaZKtCi2Ig
From Twitter survey results that approx. 25% people consider attribute size sometimes as useful. So what would be the decision ??
Majority wins.