Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony3 "The option "placeholder" does not exist."

Tags:

forms

php

symfony

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; 
like image 914
aln447 Avatar asked Dec 17 '16 16:12

aln447


1 Answers

placeholder is an HTML attribute and can be added using the TextType attr option.

$form = $this->createFormBuilder($user)
        ->add('Username', TextType::class, array(
            'label' => "Change UserName",
            'attr' => array(
                'placeholder' => $userData[0]->getUsername(),
            )
        ));
like image 51
malcolm Avatar answered Sep 23 '22 16:09

malcolm