app/Plugin/PiaContact/Form/Type/FormAppraisalType.php line 24

Open in your IDE?
  1. <?php
  2. namespace Plugin\PiaContact\Form\Type;
  3. use Eccube\Form\Type\AddressType;
  4. use Eccube\Form\Type\KanaType;
  5. use Eccube\Form\Type\NameType;
  6. use Eccube\Form\Type\PostalType;
  7. use Eccube\Form\Type\PhoneNumberType;
  8. use Eccube\Form\Type\Master\PrefType;
  9. use Symfony\Component\Form\AbstractType;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  12. use Symfony\Component\Form\Extension\Core\Type\FileType;
  13. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  15. use Symfony\Component\Form\Extension\Core\Type\TextType;
  16. use Symfony\Component\Form\FormBuilderInterface;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. /**
  19.  * 査定申込フォーム
  20.  */
  21. class FormAppraisalType extends AbstractType
  22. {
  23.     /**
  24.      * {@inheritdoc}
  25.      */
  26.     public function buildForm(FormBuilderInterface $builder, array $options)
  27.     {
  28.         $builder
  29.             ->add('kana'KanaType::class, [
  30.                 'required' => true,
  31.             ])
  32.             ->add('name'NameType::class, [
  33.                 'required' => true,
  34.             ])
  35.             ->add('zip'PostalType::class, [
  36.                 'required' => true,
  37.             ])
  38.             ->add('address'AddressType::class, [
  39.                 'required' => true,
  40.             ])
  41.             ->add('tel'PhoneNumberType::class, [
  42.                 'required' => true,
  43.             ])
  44.             ->add('email'EmailType::class, [
  45.                 'required' => true,
  46.                 'constraints' => [
  47.                     new Assert\NotBlank(),
  48.                     new Assert\Email(),
  49.                 ],
  50.             ])
  51.             ->add('contact'ChoiceType::class, [
  52.                 'label' => 'ご連絡方法',
  53.                 'choices' => [
  54.                     'TEL' => '1',
  55.                     'メール' => '2',
  56.                 ],
  57.                 'expanded' => true,
  58.                 'multiple' => false,
  59.                 'required' => false,
  60.                 'placeholder' => false,
  61.             ])
  62.             ->add('receiving'ChoiceType::class, [
  63.                 'label' => 'お受取方法',
  64.                 'choices' => [
  65.                     'ご配送' => '1',
  66.                     'ご来店' => '2',
  67.                 ],
  68.                 'expanded' => true,
  69.                 'multiple' => false,
  70.                 'required' => false,
  71.                 'placeholder' => false,
  72.             ])
  73.             ->add('contents'TextareaType::class, [
  74.                 'label' => 'メッセージ',
  75.                 'required' => false,
  76.                 'attr' => [
  77.                     'rows' => 5,
  78.                     'placeholder' => 'ご質問やご要望がございましたら、こちらにご記入ください。',
  79.                 ],
  80.             ]);
  81.         // 商品項目(5個)
  82.         for ($i 1$i <= 5$i++) {
  83.             $builder
  84.                 ->add("item0{$i}_name"TextType::class, [
  85.                     'label' => "申込コイン{$i}(名)",
  86.                     'required' => false,
  87.                     'attr' => [
  88.                         'placeholder' => '2021 イギリス クイーンズビースト£1000 1kg金貨',
  89.                         'class' => 'form-control',
  90.                     ],
  91.                 ])
  92.                 ->add("item0{$i}_num"IntegerType::class, [
  93.                     'label' => "申込コイン{$i}(数量)",
  94.                     'required' => false,
  95.                     'attr' => [
  96.                         'class' => 'form-control',
  97.                         'min' => 0,
  98.                     ],
  99.                 ])
  100.                 ->add("item0{$i}_price"IntegerType::class, [
  101.                     'label' => "申込コイン{$i}(価格(円))",
  102.                     'required' => false,
  103.                     'attr' => [
  104.                         'class' => 'form-control',
  105.                         'min' => 0,
  106.                         'placeholder' => '価格を円で入力してください',
  107.                     ],
  108.                 ])
  109.                 ->add("item0{$i}_img"FileType::class, [
  110.                     'label' => "申込コイン{$i}(画像)",
  111.                     'mapped' => false,
  112.                     'required' => false,
  113.                     'constraints' => [
  114.                         new Assert\File([
  115.                             'maxSize' => '10M',
  116.                             'maxSizeMessage' => '画像ファイルは10M以下でアップロードしてください。',
  117.                             'mimeTypes' => [
  118.                                 'image/jpeg',
  119.                                 'image/png',
  120.                                 'image/gif',
  121.                             ],
  122.                             'mimeTypesMessage' => 'JPEG、PNG、GIF形式の画像ファイルをアップロードしてください。',
  123.                         ]),
  124.                     ],
  125.                 ]);
  126.         }
  127.     }
  128.     /**
  129.      * {@inheritdoc}
  130.      */
  131.     public function getBlockPrefix()
  132.     {
  133.         return 'form_appraisal';
  134.     }
  135. }