Created
November 13, 2018 09:39
-
-
Save yahyaerturan/3e0e19725bc621ca4e7d26d853962b2b to your computer and use it in GitHub Desktop.
Form Örnek
This file contains 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
{# @var form \App\Entity\User #} | |
{% set cccc = 'col-md-3 col-sm-4 col-xs-6' %} | |
{% set ccc = 'col-md-4 col-sm-6 col-xs-12' %} | |
{% set cc = 'col-md-6 col-sm-12 col-xs-12' %} | |
{{ form_start(form, {'method': _method,'attr': {'novalidate': 'novalidate', 'autocomplete':'off'}}) }} | |
<div class="row"> | |
<div class="{{ ccc }}">{{ form_row(form.firstName) }}</div> | |
<div class="{{ ccc }}">{{ form_row(form.lastName) }}</div> | |
<div class="{{ ccc }}">{{ form_row(form.gender) }}</div> | |
<div class="{{ ccc }}">{{ form_row(form.email) }}</div> | |
<div class="{{ ccc }}">{{ form_row(form.mobileNumber) }}</div> | |
{% if form.plainPassword is defined %} | |
<div class="{{ ccc }}">{{ form_row(form.plainPassword) }}</div> | |
{% endif %} | |
<div class="{{ ccc }}">{{ form_row(form.birthday) }}</div> | |
<div class="{{ ccc }}">{{ form_row(form.nationalId) }}</div> | |
<div class="{{ ccc }}">{{ form_row(form.twitterUsername) }}</div> | |
<div class="{{ ccc }}">{{ form_row(form.business) }}</div> | |
</div> | |
<div class="row"> | |
<div class="{{ cccc }}">{{ form_row(form.isEmailOptedIn) }}</div> | |
<div class="{{ cccc }}">{{ form_row(form.isSmsOptedIn) }}</div> | |
</div> | |
{{ form_end(form) }} |
This file contains 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\Form; | |
use App\Entity\Business; | |
use App\Entity\User; | |
use Doctrine\ORM\EntityRepository; | |
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\Extension\Core\Type\BirthdayType; | |
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | |
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |
use Symfony\Component\Form\Extension\Core\Type\EmailType; | |
use Symfony\Component\Form\Extension\Core\Type\PasswordType; | |
use Symfony\Component\Form\Extension\Core\Type\TextType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
use Symfony\Component\Translation\TranslatorInterface; | |
use Symfony\Component\Validator\Constraints\Length; | |
use Symfony\Component\Validator\Constraints\NotBlank; | |
class UserRegistrationAdminFormType extends AbstractType | |
{ | |
private $translator; | |
public function __construct(TranslatorInterface $translator) | |
{ | |
$this->translator = $translator; | |
} | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('firstName', null, ['form_group_floated' => true]) | |
->add('lastName', null, ['form_group_floated' => true]) | |
->add('gender', ChoiceType::class, [ | |
'choices' => ['I don\'t want to specify' => 'u', 'Male' => 'm', 'Female' => 'f'], | |
'multiple' => false, | |
'attr' => ['class' => 'select2'], | |
'form_group_class' => 'form-group m-b-n', | |
'form_control_class' => null, | |
]) | |
->add('email', EmailType::class, [ | |
'form_group_floated' => true, | |
'help' => 'Daha sonra bu e-posta adresi ile sisteme giriş yapacaksınız.', | |
]) | |
->add('mobileNumber', null, ['form_group_floated' => true]) | |
->add('roles', ChoiceType::class, [ | |
'choices' => [ | |
'ROLE_BUSINESS_ADMINISTRATION', | |
'ROLE_ALLOWED_TO_SWITCH', | |
'ROLE_BUSINESS_SUPERUSER', | |
'ROLE_BUSINESS_ASSISTANT', | |
'ROLE_BUSINESS_USER' | |
] | |
]); | |
if (!empty($options['include_password'])) { | |
$builder->add('plainPassword', PasswordType::class, [ | |
'form_group_floated' => true, | |
'mapped' => false, | |
'constraints' => [ | |
new NotBlank([ | |
'message' => 'validators.password.blank' | |
]), | |
new Length([ | |
'min' => 5, | |
'minMessage' => 'validators.password.min' | |
]) | |
] | |
]); | |
} | |
$builder | |
->add('nationalId', null, ['form_group_floated' => true]) | |
->add('birthday', BirthdayType::class, [ | |
'input' => 'datetime', | |
'widget' => 'single_text', | |
'attr' => ['class' => 'birthday-picker'], | |
'form_group_floated' => true, | |
'html5' => false, | |
]) | |
->add('isEmailOptedIn', null, [ | |
'form_control_class' => null, | |
'form_group_class' => 'form-group', | |
]) | |
->add('isSmsOptedIn', null, [ | |
'form_control_class' => null, | |
'form_group_class' => 'form-group', | |
]) | |
->add('twitterUsername', null, [ | |
'form_group_floated' => true, | |
'attr' => ['autocomplete' => 'off'] | |
]) | |
->add('business', EntityType::class, [ | |
'class' => Business::class, | |
'query_builder' => function (EntityRepository $er) { | |
return $er->createQueryBuilder('b') | |
->orderBy('b.name', 'ASC'); | |
}, | |
'choice_label' => 'name', | |
'attr' => [ | |
'class' => 'select2', | |
'data-placeholder' => $this->translator->trans('Select a Business'), | |
'data-allow-clear' => true, | |
], | |
'placeholder' => '', | |
'form_control_class' => null, | |
]) | |
; | |
} | |
public function configureOptions(OptionsResolver $resolver) | |
{ | |
$resolver->setDefaults(array( | |
'data_class' => User::class, | |
'include_password' => false, | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment