如何在Symfony 4表单的输入中添加占位符? [英] How to add placeholder on input in Symfony 4 form?
本文介绍了如何在Symfony 4表单的输入中添加占位符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Symfony 4表单中,我尝试为我的输入获取一个占位符.我尝试了以下操作,但收到错误消息,不允许这样做.有什么想法我还能实现吗?
In my Symfony 4 form, I am try to get a placeholder for my input. I tried the below but I get an error that it is not allowed. Any ideas how else I can achieve this?
->add('firstname', TextType::class, ['label' => 'Vorname ', 'placeholder' => 'Your name',])
根据文档中的建议,在下面也尝试过,这里我没有收到错误,只是没有渲染.
As suggested in the documentation I have also tried the below, here I am not getting an error, just nothing is rendering.
->add('firstname', TextType::class, ['label' => 'Vorname '], ['attr' => ['placeholder' => 'Vorname ']])
推荐答案
您需要这样做:
->add('firstname', TextType::class, array(
'label' => 'Vorname ',
'attr' => array(
'placeholder' => 'hereYourPlaceHolder'
)
))
正如他们在文档中所说的那样
As they say in the documentation
这篇关于如何在Symfony 4表单的输入中添加占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文