Symfony2 forms interpret blank strings as nulls

前端 未结 7 2534
温柔的废话
温柔的废话 2021-02-19 09:12

I have a Symfony2 form with a variety of fields, including one optional text field called recap.

This recap field saves perfectly when there\'s

7条回答
  •  没有蜡笔的小新
    2021-02-19 09:33

    I think you're taking the problem the wrong way: when the user leaves recap blank the value is unknown because not provided . For example you don't say that an empty birthdate field means that birthdate is equaled to '' but that birthdate is unknown. Same goes for addresss, etc...

    So if your user isn't required to fill this field then it seems that the most relevant response is in fact to set your field as being nullable

提交回复
热议问题