Skip to content

Commit

Permalink
Merge branch '4' into 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Aug 15, 2023
2 parents 803b687 + 1524a4e commit 13d071f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
7 changes: 4 additions & 3 deletions en/02_Developer_Guides/03_Forms/00_Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use SilverStripe\Forms\FieldList;
$form = Form::create(
$controller, // the Controller to render this form on
$name, // name of the method that returns this form on the controller
$fields, // list of FormField instances
$actions, // list of FormAction instances
$validator // optional Validator - usually a RequiredFields object
FieldList $fields, // list of FormField instances
FieldList $actions, // list of FormAction instances
Validator $validator // optional use of Validator object
);
```

Expand Down Expand Up @@ -343,6 +343,7 @@ validating its' own data value.
For more information, see the [Form Validation](validation) documentation.

```php
use SilverStripe\Forms\Form;
use SilverStripe\Forms\RequiredFields;

$validator = new RequiredFields([
Expand Down
21 changes: 17 additions & 4 deletions en/02_Developer_Guides/03_Forms/01_Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ icon: check-square

# Form Validation

Silverstripe CMS provides server-side form validation out of the box through the [Validator](api:SilverStripe\Forms\Validator)
abstract class and validator classes (e.g. `RequiredFields`) inheriting from it.
A single `Validator` instance is set on each `Form`. Validators are implemented as an argument to
Silverstripe CMS provides server-side form validation out of the box through the [Validator](api:SilverStripe\Forms\Validator) abstract class and its' child classes
(see [available validators](#available-validators) below). A single `Validator` instance is set on each `Form`. Validators are implemented as an argument to
the [Form](api:SilverStripe\Forms\Form) constructor or through the function `setValidator`.

```php
Expand Down Expand Up @@ -208,6 +207,20 @@ class Page_Controller extends ContentController
}
```

## Available validators

The Silverstripe framework comes with the following built-in validators:

- [`CompositeValidator`](api:SilverStripe\Forms\CompositeValidator)
A container for additional validators. You can implement discrete validation logic in multiple `Validator` subclasses and apply them _all_ to a
given form by putting them inside a `CompositeValidator`. The `CompositeValidator` doesn't have perform any validation by itself.
- [`FieldsValidator`](api:SilverStripe\Forms\FieldsValidator)
Simply calls [`validate()`](api:SilverStripe\Forms\FormField::validate()) on all data fields in the form, to ensure fields have valid values.
- [`RequiredFields`](api:SilverStripe\Forms\RequiredFields)
Validates that fields you declare as "required" have a value.

There are additional validators available in community modules, and you can implement your own validators by subclassing the abstract `Validator` class.

## Validation-exempt actions

In some cases you might need to disable validation for specific actions. E.g. actions which discard submitted
Expand Down Expand Up @@ -269,7 +282,7 @@ provides a [DataObject::validate()](api:SilverStripe\ORM\DataObject::validate())
### Validation in the CMS

In the CMS, we're not creating the forms for editing CMS records. The `Form` instance is generated for us so we cannot
call `setValidator` easily. However, a `DataObject` can provide its' own `Validator` instance/s through the
call `setValidator` easily. However, a `DataObject` can provide its own `Validator` instance/s through the
`getCMSCompositeValidator()` method. The CMS interfaces such as [LeftAndMain](api:SilverStripe\Admin\LeftAndMain),
[ModelAdmin](api:SilverStripe\Admin\ModelAdmin) and [GridField](api:SilverStripe\Forms\GridField\GridField) will
respect the provided `Validator`/s and handle displaying error and success responses to the user.
Expand Down
4 changes: 1 addition & 3 deletions en/02_Developer_Guides/11_Integration/00_CSV_Import.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ use SilverStripe\Forms\Form;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FileField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Dev\CsvBulkLoader;
use SilverStripe\Control\Controller;

Expand All @@ -114,8 +113,7 @@ class MyController extends Controller
),
new FieldList(
new FormAction('doUpload', 'Upload')
),
new RequiredFields()
)
);
return $form;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use SilverStripe\Forms\Form;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FileField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\FieldsValidator;
use SilverStripe\Dev\CsvBulkLoader;
use SilverStripe\Control\Controller;

Expand Down Expand Up @@ -45,7 +45,7 @@ class MyController extends Controller
new FieldList(
new FormAction('doUpload', 'Upload')
),
new RequiredFields()
new FieldsValidator()
);
return $form;
}
Expand Down
2 changes: 1 addition & 1 deletion en/02_Developer_Guides/14_Files/04_File_Storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Changes are only tracked for file metadata (e.g. the `Title` attribute).
You can opt-in to retaining the file content for replaced or removed files.

```yml
SilverStripe\Assets\Flysystem\FlysystemAssetStore:
SilverStripe\Assets\File:
keep_archived_assets: true
```
Expand Down

0 comments on commit 13d071f

Please sign in to comment.