Skip to content

Commit 7f43200

Browse files
authored
Merge pull request #8370 from cakephp/docs/5x-modern-image-formats
Document modern image formats in forms and validation
2 parents bff2bb1 + 8d03122 commit 7f43200

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎docs/en/core-libraries/validation.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,21 @@ Core rules that take additional parameters should have an array for the
675675
`rule` key that contains the rule as the first element, and the additional
676676
parameters as the remaining parameters.
677677

678+
### File Extensions
679+
680+
`Validation::extension()` accepts `gif`, `jpeg`, `png`, `jpg`, `jxl`, `webp`,
681+
`avif` and `avifs` by default. Supply an explicit list to restrict extensions
682+
for a particular upload:
683+
684+
```php
685+
$validator->add('photo', 'extension', [
686+
'rule' => ['extension', ['jpg', 'jpeg', 'png']],
687+
]);
688+
```
689+
690+
The rule checks the filename extension, not the file's contents. Use a MIME
691+
type rule as well when you need to check the uploaded content.
692+
678693
### IP and Range Validation
679694

680695
You can validate that a value is a valid IP address or an IP range (subnet)

‎docs/en/views/helpers/form.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,8 @@ You could then use JavaScript to set the `onvalid` and `oninvalid` events as you
20202020

20212021
Creates an `input` element of `submit` type, with `$caption` as value.
20222022
If the supplied `$caption` is a URL pointing to an image (i.e. if the string
2023-
contains '://' or contains any of the extensions '.jpg, .jpe, .jpeg, .gif'),
2023+
contains '://' or ends in `.jpg`, `.jpe`, `.jpeg`, `.jxl`, `.gif`, `.png`,
2024+
`.webp`, `.ico`, `.avif` or `.avifs`),
20242025
an image submit button will be generated, using the specified image if it
20252026
exists. If the first character is '/' then the image path is relative to
20262027
*webroot*, else if the first character is not '/' then the image path is

0 commit comments

Comments
 (0)