Version 3
end of life
This version of Silverstripe CMS will not recieve any additional bug fixes or documentation updates.
Go to documentation for the most recent stable version.
Read-only and Disabled Forms
Form and FormField instances can be turned into a read-only version for things like confirmation pages or
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
.
To make an entire Form read-only.
$form = new Form(..);
$form->makeReadonly();
To make all the fields within a FieldList read-only (i.e to make fields read-only but not buttons).
$fields = new FieldList(..);
$fields = $fields->makeReadonly();
To make a FormField read-only you need to know the name of the form field or call it direct on the object
$field = new TextField(..);
$field = $field->performReadonlyTransformation();
$fields = new FieldList(
$field
);
// Or,
$field = new TextField(..);
$field->setReadonly(true);
$fields = new FieldList(
$field
);
Disabling FormField instances, sets the disabled
property on the class. This will use the same HTML markup as
a normal form, but set the disabled
attribute on the input
tag.