money Field Type¶
Renders an input text field and specializes in handling submitted “money” data.
This field type allows you to specify a currency, whose symbol is rendered next to the text field. There are also several other options for customizing how the input and output of the data is handled.
Rendered as | input text field |
Options | |
Inherited options | |
Parent type | field |
Class | Symfony\Component\Form\Extension\Core\Type\MoneyType |
Field Options¶
currency¶
type: string default: EUR
Specifies the currency that the money is being specified in. This determines the currency symbol that should be shown by the text box. Depending on the currency - the currency symbol may be shown before or after the input text field.
This can also be set to false to hide the currency symbol.
divisor¶
type: integer default: 1
If, for some reason, you need to divide your starting value by a number before rendering it to the user, you can use the divisor option. For example:
$builder->add('price', 'money', array(
'divisor' => 100,
));
In this case, if the price field is set to 9900, then the value 99 will actually be rendered to the user. When the user submits the value 99, it will be multiplied by 100 and 9900 will ultimately be set back on your object.
precision¶
type: integer default: 2
For some reason, if you need some precision other than 2 decimal places, you can modify this value. You probably won’t need to do this unless, for example, you want to round to the nearest dollar (set the precision to 0).
grouping¶
type: integer default: false
The value set as the NumberFormatter::GROUPING_USED attribute when using the PHP NumberFormatter class.
Inherited Options¶
These options inherit from the field type:
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.
label¶
type: string default: The label is “guessed” from the field name
Sets the label that will be used when rendering the field. The label can also be directly set inside the template:
{{ render_label(form.name, 'Your name') }}
read_only¶
type: Boolean default: false
If this option is true, the field will be rendered with the disabled attribute so that the field is not editable.
error_bubbling¶
type: Boolean default: false
If true, any errors for this field will be passed to the parent field or form. For example, if set to true on a normal field, any errors for that field will be attached to the main form, not to the specific field.