从Symfony表单中删除标签

时间:2017-01-25 21:15:18

标签: symfony

我正在使用Symfony表单,我试图删除已出现的标签或将其更改为接受空格的文本行。在这种情况下,标签是Response a,它是表单的名称。

实体:

protected $responseA;

public function getResponseA()
{
    return $this->responseA;
}

public function setResponseA($responseA)
{
    $this->task = $responseA;
}

表格的控制器:

$responseA = new Applicant();
$responseA->setResponseA('');

$form = $this->createFormBuilder($responseA)
    ->add('responseA', ChoiceType::class, array(
        'choices' => array(
            'Very Acceptable' => '1',
            'Acceptable' => '2',
            'Inappropriate' => '3',
            'Very Inappropriate' => '4'
        ),
    ))
    ->add('save', SubmitType::class, array('label' => 'Create Post'))
    ->getForm();

我想删除或更改内容:

enter image description here

3 个答案:

答案 0 :(得分:1)

Set 'label' value to false将取消标签显示。

$ responseA = new Applicant(); $ responseA-> setResponseA( '');

$form = $this->createFormBuilder($responseA)
    ->add('responseA', ChoiceType::class, array(
        'choices' => array(
            'Very Acceptable'    => '1',
            'Acceptable'         => '2',
            'Inappropriate'      => '3',
            'Very Inappropriate' => '4'
        ),
        'label'   => false,
    ))
    ->add('save', SubmitType::class, array('label' => 'Create Post'))
    ->getForm();

答案 1 :(得分:0)

我认为你需要这样的东西:

$form = $this->createFormBuilder($responseA)
    ->add('responseA', ChoiceType::class, array(
        'choices' => array(
            'Very Acceptable' => '1',
            'Acceptable' => '2',
            'Inappropriate' => '3',
            'Very Inappropriate' => '4'
        ),
        'label' => '',
    ))
    ->add('save', SubmitType::class, array('label' => 'Create Post'))
    ->getForm();

请注意,label选项设置为空字符串。

答案 2 :(得分:0)

您也可以在模板中通过省略某些字段的form_label来执行此操作:

{{ form_start(form) }}
    {{ form_errors(form.responseA) }}
    {{ form_widget(form.responseA) }}
    {{ form_widget(form.save) }}
{{ form_end(form) }}