Skip to content

Commit

Permalink
Merge pull request #652 from creative-commoners/pulls/6.0/remove-fiel…
Browse files Browse the repository at this point in the history
…dsvalidator

DOC Remove references to FieldsValidator
  • Loading branch information
GuySartorelli authored Dec 12, 2024
2 parents dccb05f + 7285d00 commit b199871
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 6 additions & 6 deletions en/02_Developer_Guides/03_Forms/01_Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ icon: check-square
> Before you start implementing custom validation logic, check out [validation using `symfony/validator` constraints](/developer_guides/model/validation/#validation-and-constraints)
> and see if there's an existing constraint that can do the heavy lifting for you.
Silverstripe CMS provides server-side form validation out of the box through the [Validator](api:SilverStripe\Forms\Validation\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`.
Silverstripe CMS provides server-side form validation out of the box in a couple of ways:

- Firstly, when a [`Form`](api:SilverStripe\Forms\Form) is submitted, the [`FormField::validate()`](api:SilverStripe\Forms\FormField::validate()) method is called on each [FormField](api:SilverStripe\Forms\FormField) instance within the form.
- Secondly, an instance of [Validator](api:SilverStripe\Forms\Validation\Validator) sublass can be set on each `Form`. Validators are implemented as an argument to the [Form](api:SilverStripe\Forms\Form) constructor or through the function `setValidator`.

```php
namespace App\PageType;
Expand All @@ -38,14 +39,15 @@ class MyFormPageController extends PageController
{
$fields = FieldList::create(
TextField::create('Name'),
// EmailField::validate() will validate the submitted value is a valid email address
EmailField::create('Email')
);

$actions = FieldList::create(
FormAction::create('doSubmitForm', 'Submit')
);

// the fields 'Name' and 'Email' are required.
// RequiredFieldsValidator marks the fields 'Name' and 'Email' as required.
$required = RequiredFieldsValidator::create([
'Name', 'Email',
]);
Expand Down Expand Up @@ -265,8 +267,6 @@ The Silverstripe framework comes with the following built-in validators:
- [`CompositeValidator`](api:SilverStripe\Forms\Validation\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.
- [`RequiredFieldsValidator`](api:SilverStripe\Forms\Validation\RequiredFieldsValidator)
Validates that fields you declare as "required" have a value.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use App\Model\MyDataObject;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\CsvBulkLoader;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FieldsValidator;
use SilverStripe\Forms\FileField;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
Expand Down Expand Up @@ -46,8 +45,7 @@ class MyController extends Controller
),
FieldList::create(
FormAction::create('doUpload', 'Upload')
),
FieldsValidator::create()
)
);
return $form;
}
Expand Down

0 comments on commit b199871

Please sign in to comment.