Created
September 25, 2020 09:09
-
-
Save netraagal/3f423325f86c092e3f64fdcf0c23d237 to your computer and use it in GitHub Desktop.
Symfony form - Radio button in list view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends template %} | |
{% block content %} | |
{{ form_start(form, {'attr' : {'class': 'user_profile_edit'}}) }} | |
<div class="row"> | |
<div class="col-md-4">{{ form_row(form.firstName) }}</div> | |
<div class="col-md-4">{{ form_row(form.lastName) }}</div> | |
<div class="col-md-4">{{ form_row(form.email) }}</div> | |
</div> | |
<br> | |
<div class="row"> | |
<div class="col-xs-offset-1 col-xs-11"> | |
{{ form_label((form.sendMails)) }} | |
</div> | |
<div class="col-xs-offset-1 col-xs-11"> | |
{# | |
This part allows to display in list | |
and not in line | |
#} | |
{% for child in form.sendMails %} | |
<div> | |
{{ form_widget(child) }} | |
{{ form_label(child) }} | |
</div> | |
{% endfor %} | |
</div> | |
</div> | |
<br> | |
<div class="actions center"> | |
{{ form_rest(form) }} | |
</div> | |
</form> | |
{% endblock content %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\UserBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |
class EditFormType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('firstName', 'text', [ | |
'label' => 'form.first_name', | |
'required' => true, | |
'attr' => [ | |
'class' => 'form-control', | |
] | |
]) | |
->add('lastName', 'text', [ | |
'label' => 'form.last_name', | |
'required' => true, | |
'attr' => [ | |
'class' => 'form-control', | |
] | |
]) | |
->add('email', 'text', [ | |
'label' => 'form.email', | |
'required' => true, | |
'attr' => [ | |
'class' => 'form-control', | |
] | |
]) | |
// to set a radio button | |
// use ChoiceType | |
// with parameters | |
// multiple = false | |
// expanded = true | |
->add('sendMails', ChoiceType::class, [ | |
'label' => 'form.send_mail', | |
'choices' => [ | |
'form.no' => 0, | |
'form.yes' => 1, | |
], | |
'choices_as_values' => true, | |
'multiple' => false, | |
'expanded' => true, | |
]) | |
->add('submit', 'submit', [ | |
'label' => 'form.submit', | |
'attr' => [ | |
'class' => 'btn btn-primary' | |
] | |
]) | |
; | |
} | |
public function getName() | |
{ | |
return 'view_edit_user'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment