我需要带有其他字段的单选按钮,当用户选择其他并在字段中写入一些文本并提交表单时,我将其设置为字段中的文本。我有表格:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('reason', 'choice', array(
'choices' => array(
'I’m not interested in projects, I receive here' => 'I’m not interested in projects, I receive here',
'I really don’t like your service' => 'I really don’t like your service',
'I never signed up for this mailing list' => 'I never signed up for this mailing list',
'I no longer want to receive these emails' => 'I no longer want to receive these emails',
'other' => 'other'
),
'multiple' => false,
'expanded' => true,
'required' => true
))
->add('submit', 'submit');
;
}
在树枝上
{{ form_start(form, {'action': path('developers_resubscribe', {'token': token, 'id': unsubscribe.id }), 'method': 'POST'}) }}
{{ form_errors(form) }}
{{ form_row(form.reason) }}
{{ form_row(form.submit, { 'label': 'Submit me' }) }}
{{ form_end(form) }}
我不明白当用户为用户原因选择其他字段时,如何在此表单字段中添加 - 例如screen
我的行动:
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
$em->persist($unsubscribe);
$em->flush();
return $this->redirect($this->generateUrl('developers_resubscribe', array('token' => $token, 'id' => $unsubscribe->getId())));
}
}
请帮助