Removing a label from a Symfony form
我正在使用 Symfony 表单,我正在尝试删除已出现的标签或将其更改为接受空格的文本行。本例中的标签为 Response a,即表单的名称。
实体:
1 2 3 4 5 6 7 8 9 10 11 | protected $responseA; public function getResponseA() { return $this->responseA; } public function setResponseA($responseA) { $this->task = $responseA; } |
表单控制器:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $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(); |
我要删除或更改的内容:
将 \\'label\\' 值设置为 false 将抑制标签显示。
$responseA = 新申请人();
$responseA->setResponseA(\\'\\');
1 2 3 4 5 6 7 8 9 10 11 12 | $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 2 3 4 5 | {{ form_start(form) }} {{ form_errors(form.responseA) }} {{ form_widget(form.responseA) }} {{ form_widget(form.save) }} {{ form_end(form) }} |