2014-10-19 10:32:34 +02:00
title: Form Transformations
summary: Provide read-only and disabled views of your Form data.
# Read-only and Disabled Forms
2017-07-03 03:22:12 +02:00
[Form ](api:SilverStripe\Forms\Form ) and [FormField ](api:SilverStripe\Forms\FormField ) instances can be turned into a read-only version for things like confirmation pages or
2014-10-19 10:32:34 +02:00
when certain fields cannot be edited due to permissions. Creating the form is done the same way and markup is similar,
`readonly` mode converts the `input` , `select` and `textarea` tags to static HTML elements like `span` .
2017-07-03 03:22:12 +02:00
To make an entire [Form ](api:SilverStripe\Forms\Form ) read-only.
2014-10-19 10:32:34 +02:00
2017-08-03 02:51:32 +02:00
```php
2017-10-27 04:38:27 +02:00
use SilverStripe\Forms\Form;
2017-10-26 02:22:02 +02:00
2017-10-27 04:38:27 +02:00
$form = new Form(..);
$form->makeReadonly();
2017-08-03 02:51:32 +02:00
```
2014-10-19 10:32:34 +02:00
2017-07-03 03:22:12 +02:00
To make all the fields within a [FieldList ](api:SilverStripe\Forms\FieldList ) read-only (i.e to make fields read-only but not buttons).
2014-10-19 10:32:34 +02:00
2017-08-03 02:51:32 +02:00
```php
2017-10-27 04:38:27 +02:00
use SilverStripe\Forms\FieldList;
2017-10-26 02:22:02 +02:00
2017-10-27 04:38:27 +02:00
$fields = new FieldList(..);
$fields = $fields->makeReadonly();
2017-08-03 02:51:32 +02:00
```
2014-10-19 10:32:34 +02:00
2017-07-03 03:22:12 +02:00
To make a [FormField ](api:SilverStripe\Forms\FormField ) read-only you need to know the name of the form field or call it direct on the object
2014-10-19 10:32:34 +02:00
2017-08-03 02:51:32 +02:00
```php
2017-10-27 04:38:27 +02:00
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\FieldList;
$field = new TextField(..);
$field = $field->performReadonlyTransformation();
$fields = new FieldList(
$field
);
// Or,
$field = new TextField(..);
$field->setReadonly(true);
$fields = new FieldList(
$field
);
2017-08-03 02:51:32 +02:00
```
2014-10-19 10:32:34 +02:00
## Disabled FormFields
2017-07-03 03:22:12 +02:00
Disabling [FormField ](api:SilverStripe\Forms\FormField ) instances, sets the `disabled` property on the class. This will use the same HTML markup as
2014-10-19 10:32:34 +02:00
a normal form, but set the `disabled` attribute on the `input` tag.
2017-08-03 02:51:32 +02:00
```php
2017-10-27 04:38:27 +02:00
$field = new TextField(..);
$field->setDisabled(true);
2014-10-19 10:32:34 +02:00
2017-10-27 04:38:27 +02:00
echo $field->forTemplate();
2017-08-03 02:51:32 +02:00
2017-10-27 04:38:27 +02:00
// returns '< input type = "text" class = "text" . . disabled = "disabled" / > '
```