dongwu8653 2016-12-17 16:14
浏览 21
已采纳

Symfony3“选项”占位符“不存在。”

I want to create a user settings panel.

In the form I would like to have a placeholder with the current value the user has for his param.

Here is a sample code:

//...

$form = $this->createFormBuilder($user)
            ->add('Username', TextType::class, array(
                'label' => "Change UserName",
                'placeholder' => $userData[0]->getUsername()
            ))
//...

Using such values I get this error in the browser:

The option "placeholder" does not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

The problem is only with the parameter itself because 'data' => $userData[0]->getUsername() works and displays the correct information.

Here are the use parameters of my page:

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use AppBundle\Entity\Task;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use AppBundle\Entity\Post;
use AppBundle\Entity\User; 
  • 写回答

1条回答 默认 最新

  • doupao1530 2016-12-17 16:19
    关注

    placeholder is a html attribute.

    $form = $this->createFormBuilder($user)
            ->add('Username', TextType::class, array(
                'label' => "Change UserName",
                'attr' => array(
                    'placeholder' => $userData[0]->getUsername()
                    )
                )
            )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致