src/Form/Type/ContactType.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form\Type;
  3. use App\Entity\Location;
  4. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\Email;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. use Symfony\Component\Validator\Constraints\Regex;
  14. /**
  15.  * @author Kazuyuki Hayashi <kaz@noop.co.jp>
  16.  */
  17. class ContactType extends AbstractType
  18. {
  19.     public function buildForm(FormBuilderInterface $builder, array $options)
  20.     {
  21.         $builder
  22.             ->add('name'TextType::class, [
  23.                 'constraints' => [new NotBlank(['message' => '名前を入力してください。'])],
  24.                 'attr' => [
  25.                     'class' => 'text',
  26.                 ],
  27.             ])
  28.             ->add('tel'TextType::class, [
  29.                 'constraints' => [
  30.                     new NotBlank(['message' => '電話番号を入力してください。']),
  31.                     new Regex(['message' => '電話番号を半角数字のみで入力してください''pattern' => '/^[0-9]+$/'])
  32.                 ],
  33.                 'attr' => [
  34.                     'class' => 'text',
  35.                 ],
  36.             ])
  37.             ->add('email'EmailType::class, [
  38.                 'constraints' => [new NotBlank(), new Email()],
  39.                 'attr' => [
  40.                     'class' => 'text',
  41.                 ],
  42.             ])
  43.             ->add('content'TextareaType::class, [
  44.                 'constraints' => [new NotBlank(['message' => '本文を入力してください。'])],
  45.                 'attr' => [
  46.                     'class' => 'textbox',
  47.                 ],
  48.             ])
  49.         ;
  50.     }
  51.     public function configureOptions(OptionsResolver $resolver)
  52.     {
  53.         $resolver->setDefaults([
  54.             //            'data_class' =>
  55.         ]);
  56.     }
  57. }