app/Customize/Form/Type/ContactType.php line 39

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Form\Type;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Form\Type\AddressType;
  15. use Eccube\Form\Type\PhoneNumberType;
  16. use Eccube\Form\Type\PostalType;
  17. use Eccube\Form\Type\RepeatedEmailType;
  18. use Eccube\Form\Type\SimpleAddressType;
  19. use Eccube\Form\Validator\Email;
  20. use Symfony\Component\Form\AbstractType;
  21. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  22. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  23. use Symfony\Component\Form\Extension\Core\Type\RadioType;
  24. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  25. use Symfony\Component\Form\Extension\Core\Type\TextType;
  26. use Symfony\Component\Form\Extension\Core\Type\UrlType;
  27. use Symfony\Component\Form\FormBuilderInterface;
  28. use Symfony\Component\Form\FormError;
  29. use Symfony\Component\Form\FormEvent;
  30. use Symfony\Component\Form\FormEvents;
  31. use Symfony\Component\Validator\Constraints as Assert;
  32. /**
  33.  * Class ContactType
  34.  */
  35. class ContactType extends AbstractType
  36. {
  37.     /**
  38.      * @var EccubeConfig
  39.      */
  40.     protected $eccubeConfig;
  41.     /**
  42.      * ForgotType constructor.
  43.      *
  44.      * @param EccubeConfig $eccubeConfig
  45.      */
  46.     public function __construct(EccubeConfig $eccubeConfig)
  47.     {
  48.         $this->eccubeConfig $eccubeConfig;
  49.     }
  50.     /**
  51.      * {@inheritdoc}
  52.      */
  53.     public function buildForm(FormBuilderInterface $builder, array $options)
  54.     {
  55.         /** フォーム項目設定 */
  56.         #region
  57.         $builder
  58.             ->add('company_name'TextType::class, [
  59.                 'required' => true,
  60.             ])
  61.             ->add('representative_name'TextType::class, [
  62.                 'required' => true,
  63.             ])
  64.             ->add('contact_person_name'TextType::class, [
  65.                 'required' => false,
  66.             ])
  67.             ->add('postal_code'PostalType::class)
  68.             ->add('address'SimpleAddressType::class)
  69.             ->add('phone_number'PhoneNumberType::class, [
  70.                 'required' => true,
  71.             ])
  72.             ->add('email'EmailType::class)
  73.             ->add('fax_number'PhoneNumberType::class, [
  74.                 'required' => false,
  75.             ])
  76.             ->add('url'UrlType::class, [
  77.                 'required' => false,
  78.             ])
  79.             ->add('business_form'ChoiceType::class, [
  80.                 'choices'     => [
  81.                     '個人事業'    => '個人事業',
  82.                     '法人'    => '法人',
  83.                     'その他' => 'その他',
  84.                 ],
  85.                 'required'    => false,
  86.                 'multiple'    => false,
  87.                 'expanded'    => false,
  88.                 'mapped'      => true,
  89.                 'placeholder' => '選択してください',
  90.             ])
  91.             ->add('business_form_other'TextType::class, [
  92.                 'required' => false,
  93.             ])
  94.             ->add('sales_form'ChoiceType::class, [
  95.                 'choices'     => [
  96.                     '実店舗'    => '実店舗',
  97.                     'ネット'    => 'ネット',
  98.                     '卸売り'    => '卸売り',
  99.                     'その他' => 'その他',
  100.                 ],
  101.                 'required'    => false,
  102.                 'multiple'    => false,
  103.                 'expanded'    => false,
  104.                 'mapped'      => true,
  105.                 'placeholder' => '選択してください',
  106.             ])
  107.             ->add('sales_form_other'TextType::class, [
  108.                 'required' => false,
  109.             ])
  110.             ->add('use_case'ChoiceType::class, [
  111.                 'choices'     => [
  112.                     '出品'    => '出品',
  113.                     '仕入'    => '仕入',
  114.                     '両方'    => '両方',
  115.                     '検討中'    => '検討中',
  116.                 ],
  117.                 'required'    => true,
  118.                 'multiple'    => false,
  119.                 'expanded'    => false,
  120.                 'mapped'      => true,
  121.                 'placeholder' => '選択してください',
  122.             ])
  123.             ->add('selling_schedule'ChoiceType::class, [
  124.                 'choices'     => [
  125.                     '楽器'    => '楽器',
  126.                     'その他'    => 'その他',
  127.                 ],
  128.                 'required'    => false,
  129.                 'multiple'    => false,
  130.                 'expanded'    => false,
  131.                 'mapped'      => true,
  132.                 'placeholder' => '選択してください',
  133.             ])
  134.             ->add('selling_schedule_other'TextType::class, [
  135.                 'required' => false,
  136.             ])
  137.             ->add('experience'ChoiceType::class, [
  138.                 'choices'     => [
  139.                     '初めて'    => '初めて',
  140.                     'ネットは初めて'    => 'ネットは初めて',
  141.                     '他に参加有'    => '他に参加有',
  142.                 ],
  143.                 'required'    => false,
  144.                 'multiple'    => false,
  145.                 'expanded'    => false,
  146.                 'mapped'      => true,
  147.                 'placeholder' => '選択してください',
  148.             ])
  149.             ->add('chance'ChoiceType::class, [
  150.                 'choices'     => [
  151.                     'ご紹介'    => 'ご紹介',
  152.                     'ネット'    => 'ネット',
  153.                 ],
  154.                 'required'    => false,
  155.                 'multiple'    => false,
  156.                 'expanded'    => true,
  157.                 'mapped'      => true,
  158.                 'placeholder'  => false,
  159.             ])
  160.             ->add('chance_other'TextType::class, [
  161.                 'required' => false,
  162.             ])
  163.             ->add('remarks'TextareaType::class, [
  164.                 'required' => false,
  165.                 'attr' => [
  166.                     'maxlength' => 1000,
  167.                 ],
  168.             ]);
  169.         #endregion
  170.         
  171.         /** フォームリスナー */
  172.         #region
  173.         $builder
  174.         ->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event){
  175.             $businessForm $event->getForm()->get('business_form');
  176.             $businessFormOther $event->getForm()->get('business_form_other');
  177.             if( $businessForm->getData() === "その他" && empty($businessFormOther->getData())){
  178.                 $businessFormOther->addError(new FormError('事業形態が「その他」の場合はご記入ください'));
  179.             }
  180.             $salesForm $event->getForm()->get('sales_form');
  181.             $salesFormOther $event->getForm()->get('sales_form_other');
  182.             if( $salesForm->getData() === "その他" && empty($salesFormOther->getData())){
  183.                 $salesFormOther->addError(new FormError('営業形態が「その他」の場合はご記入ください'));
  184.             }
  185.             $sellingSchedule $event->getForm()->get('selling_schedule');
  186.             $sellingScheduleOther $event->getForm()->get('selling_schedule_other');
  187.             if( $sellingSchedule->getData() === "その他" && empty($sellingScheduleOther->getData())){
  188.                 $sellingScheduleOther->addError(new FormError('売買予定商品が「その他」の場合はご記入ください'));
  189.             }
  190.             $chance $event->getForm()->get('chance');
  191.             $chanceOther $event->getForm()->get('chance_other');
  192.             if( $chance->getData() === "ご紹介" && empty($chanceOther->getData())){
  193.                 $chanceOther->addError(new FormError('ご参加のきっかけが「ご紹介」の場合はご記入ください'));
  194.             }
  195.         });
  196.         #endregion
  197.     }
  198.     /**
  199.      * {@inheritdoc}
  200.      */
  201.     public function getBlockPrefix()
  202.     {
  203.         return 'forgot';
  204.     }
  205. }