php - Symfony3 "The option "占位符“不存在”。

标签 php forms symfony

我想创建一个用户设置面板。

在表单中,我希望有一个占位符,其中包含用户为其参数设置的当前值。

这是一个示例代码:

//...

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

使用这样的值我在浏览器中得到这个错误:

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".

问题仅出在参数本身,因为 'data' => $userData[0]->getUsername() 工作并显示正确的信息。

我的页面使用参数如下:

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; 

最佳答案

placeholder 是一个 HTML 属性,可以使用 TextType attr 添加选项。

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

关于php - Symfony3 "The option "占位符“不存在”。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41200549/

相关文章:

c++ - Visual C++ 窗体应用程序错误 : C3374

php - 使用 PHP 提供私有(private)图像

php - 在 null [LARAVEL] 上调用成员函数 update()

php - 为什么 PHP $_SERVER 变量中的 HTTP 响应代码不可用?

php - 使用 Symfony Process 运行后台任务,无需等待进程完成

symfony - 在 Symfony2 中组织业务逻辑

php - 在不登录用户的情况下使用 FOSUserBundle 注册用户

php - 无法加载 "Symfony\Bridge\Twig\Form\TwigRenderer"运行时

javascript - 使用javascript在Enter键上提交表单

forms - TinyMCE 获取表单内容而不使用提交按钮