]> Raphaƫl G. Git Repositories - blogbundle/blob - Form/ContactType.php
Add group entity
[blogbundle] / Form / ContactType.php
1 <?php
2
3 namespace Rapsys\BlogBundle\Form;
4
5 use Symfony\Component\Form\AbstractType;
6 use Symfony\Component\Form\FormBuilderInterface;
7 use Symfony\Component\OptionsResolver\OptionsResolver;
8 use Symfony\Component\Form\Extension\Core\Type\TextType;
9 use Symfony\Component\Form\Extension\Core\Type\TextareaType;
10 use Symfony\Component\Form\Extension\Core\Type\EmailType;
11 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
12 use Symfony\Component\Validator\Constraints\Email;
13 use Symfony\Component\Validator\Constraints\NotBlank;
14
15 class ContactType extends AbstractType {
16 /**
17 * {@inheritdoc}
18 */
19 public function buildForm(FormBuilderInterface $builder, array $options) {
20 return $builder->add('name', TextType::class, array('attr' => array('placeholder' => 'Your name'), 'constraints' => array(new NotBlank(array("message" => "Please provide your name")))))
21 ->add('subject', TextType::class, array('attr' => array('placeholder' => 'Subject'), 'constraints' => array(new NotBlank(array("message" => "Please give a Subject")))))
22 ->add('email', EmailType::class, array('attr' => array('placeholder' => 'Your email address'), 'constraints' => array(new NotBlank(array("message" => "Please provide a valid email")), new Email(array("message" => "Your email doesn't seems to be valid")))))
23 ->add('message', TextareaType::class, array('attr' => array('placeholder' => 'Your message here', 'cols' => 50, 'rows' => 15), 'constraints' => array(new NotBlank(array("message" => "Please provide a message here")))))
24 ->add('submit', SubmitType::class, array('label' => 'Send', 'attr' => array('class' => 'submit')));
25 }
26
27 /**
28 * {@inheritdoc}
29 */
30 public function setDefaultOptions(OptionsResolver $resolver) {
31 $resolver->setDefaults(array('error_bubbling' => true));
32 }
33
34 /**
35 * {@inheritdoc}
36 */
37 public function getName() {
38 return 'contact_form';
39 }
40 }