T
T
Think With Your Head2016-09-14 14:05:08
symfony
Think With Your Head, 2016-09-14 14:05:08

How to set the default value in the symphony form field if it is empty?

Hello.
Is there a built-in method, if the database is null, then the corresponding form field is set to the default value (not placeholder, but value) when rendering.
I tried to set it through the 'data' property, but if the field in the database is filled anyway, the default value is set (from 'data'), but it is necessary, if there is a value in the database, then display it as the value of this field.
A separate question is how to fill in the value of the textarea fields, since it has its own nuances (the default value is the content inside the tag, as you know, and not the value attribute like inputs)
If there is no built-in solution, then of course you have to write a function - tell me where it is better to arrange it in terms of architecture, in the form class or something else?
Thanks

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Arthur, 2016-09-14
@thinkbrain2

if($value):echo $value; else: ''; endif;

W
WQP, 2016-09-14
@WQP

echo ($value?$value:'');

D
dimarick, 2016-09-17
@dimarick

If it is necessary simply - initialize the form immediately with the necessary values ​​in the $data parameter. If not suitable, use DataTransformers and define the logic for displaying values ​​in the base to values ​​in the UI and vice versa.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question