Reputation:
I'm using a Symfony form and I am trying to either remove the label that has appeared or change it to a line of text which accepts spaces. The label in this case is Response a, which is the name of the form.
Entity:
protected $responseA;
public function getResponseA()
{
return $this->responseA;
}
public function setResponseA($responseA)
{
$this->task = $responseA;
}
Controller for the form:
$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();
What I would like to remove or change:
Upvotes: 0
Views: 2410
Reputation: 4363
Set 'label' value to false will suppress the label display.
$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();
Upvotes: 4
Reputation:
You can also do it in the template by ommiting the form_label
for some fields:
{{ form_start(form) }}
{{ form_errors(form.responseA) }}
{{ form_widget(form.responseA) }}
{{ form_widget(form.save) }}
{{ form_end(form) }}
Upvotes: 0