diff --git a/en/02_Developer_Guides/03_Forms/00_Introduction.md b/en/02_Developer_Guides/03_Forms/00_Introduction.md index f693b9551..530ad8cbf 100644 --- a/en/02_Developer_Guides/03_Forms/00_Introduction.md +++ b/en/02_Developer_Guides/03_Forms/00_Introduction.md @@ -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 ); ``` @@ -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([ diff --git a/en/02_Developer_Guides/03_Forms/01_Validation.md b/en/02_Developer_Guides/03_Forms/01_Validation.md index 06252b072..15799da65 100644 --- a/en/02_Developer_Guides/03_Forms/01_Validation.md +++ b/en/02_Developer_Guides/03_Forms/01_Validation.md @@ -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 @@ -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 @@ -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. diff --git a/en/02_Developer_Guides/11_Integration/00_CSV_Import.md b/en/02_Developer_Guides/11_Integration/00_CSV_Import.md index fd9dfba41..655a017c3 100644 --- a/en/02_Developer_Guides/11_Integration/00_CSV_Import.md +++ b/en/02_Developer_Guides/11_Integration/00_CSV_Import.md @@ -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; @@ -114,8 +113,7 @@ class MyController extends Controller ), new FieldList( new FormAction('doUpload', 'Upload') - ), - new RequiredFields() + ) ); return $form; } diff --git a/en/02_Developer_Guides/11_Integration/How_Tos/Import_CSV_through_a_Controller.md b/en/02_Developer_Guides/11_Integration/How_Tos/Import_CSV_through_a_Controller.md index 2fb8d699e..c79d62eb1 100644 --- a/en/02_Developer_Guides/11_Integration/How_Tos/Import_CSV_through_a_Controller.md +++ b/en/02_Developer_Guides/11_Integration/How_Tos/Import_CSV_through_a_Controller.md @@ -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; @@ -45,7 +45,7 @@ class MyController extends Controller new FieldList( new FormAction('doUpload', 'Upload') ), - new RequiredFields() + new FieldsValidator() ); return $form; } diff --git a/en/02_Developer_Guides/14_Files/04_File_Storage.md b/en/02_Developer_Guides/14_Files/04_File_Storage.md index 8b1dd812e..4b7fae62f 100644 --- a/en/02_Developer_Guides/14_Files/04_File_Storage.md +++ b/en/02_Developer_Guides/14_Files/04_File_Storage.md @@ -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 ```