Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
アンケートのフォームタイプ
<?php
namespace Customize\Form;
use Customize\Entity\Questionnaire;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CreateQuestionnaire extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
switch ($options['flow_step']) {
case 1:
$builder->add('q1', ChoiceType::class, [
'choices' => ["男性" => "男性", "女性" => "女性", "その他" => "その他"],
'expanded' => true,
'multiple' => false
]);
break;
case 2:
$values = array_map(function ($age) {
return $age."代";
}, range(10, 90, 10));
$builder->add('q2', ChoiceType::class, [
'choices' => array_combine($values, $values) + ["それ以上" => "それ以上"],
'placeholder' => 'common.select'
]);
break;
case 3:
$builder->add('q3', TextareaType::class, [
'required' => false
]);
break;
}
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Questionnaire::class
]);
}
/**
* @return string|null
*/
public function getBlockPrefix()
{
return 'createQuestionnaire';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment