FOSUser Bundle Adding PlaceHolder to form element

我是研究僧i 提交于 2019-12-11 09:15:21

问题


I understand that when you are overriding FOSUser Bundle Forms, you follow this structure;

{{ form_widget(form.plainPassword.first, { 'attr': {'class': 'myformclass'} }) }}

I also want to add PlaceHolder option to my form element.. How can i do that?

so it will look like something like this;

<input class="myformclass" placeholder="Password" type="password" id="password" name="_password" required="required" />

回答1:


{{ form_widget(form.plainPassword.first, { 'attr': {'class': 'myformclass', 'placeholder': 'Password', 'id': password'}}) }}

Field name depends on your form name

it will like be named this for fosuser bundle register form

fos_user_registration_form[plainPassword][password]

the id will be

fos_user_registration_form_plainPassword_password

You can override "id" like written in my example

Required and name options are defined in the form class




回答2:


You can use the placeholder attribute.

METHOD 1: Twig

{{ form_widget(form.plainPassword.first, { 'attr': {'placeholder': 'enter your password'} }) }}

METHOD 2: Form Builder

$builder
    ->add('plainPassword', null , array(
        'attr'=> 
            array('placeholder'=>'enter your password')
        )
    );


来源:https://stackoverflow.com/questions/14741084/fosuser-bundle-adding-placeholder-to-form-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!