抽象的な「field」タイプ¶
field は単体で用いられるフォームタイプではありません。 他の多くのフォームタイプの為に用意された、親フォームタイプです。
field は事前にいくつかのオプションを定義します:
data¶
type: mixed default: Defaults to field of the underlying object (if there is one)
When you create a form, each field initially displays the value of the corresponding property of the form’s domain object (if an object is bound to the form). If you want to override the initial value for the form or just and individual field, you can set it in the data option:
$builder->add('token', 'hidden', array(
'data' => 'abcdef',
));
required¶
type: Boolean default: true
If true, an HTML5 required attribute will be rendered. The corresponding label will also render with a required class.
This is superficial and independent from validation. At best, if you let Symfony guess your field type, then the value of this option will be guessed from your validation information.
-
disabled [type: Boolean, default: false] If you don’t want a user to modify the value of a field, you can set the disabled option to true. Any submitted value will be ignored.
use Symfony\Component\Form\TextField $field = new TextField('status', array( 'data' => 'Old data', 'disabled' => true, )); $field->submit('New data'); // prints "Old data" echo $field->getData();
trim¶
type: Boolean default: true
If true, the whitespace of the submitted string value will be stripped via the trim() function when the data is bound. This guarantees that if a value is submitted with extra whitespace, it will be removed before the value is merged back onto the underlying object.
-
property_path [type: any, default: the field’s value] Fields display a property value of the form’s domain object by default. When the form is submitted, the submitted value is written back into the object.
If you want to override the property that a field reads from and writes to, you can set the property_path option. Its default value is the field’s name.