<?php
// src/Form/ContactFormType.php
namespace App\Form;
use App\Entity\TCodpos;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
class ContactoFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPreSetData'));
}
function onPreSetData(FormEvent $event)
{
$form = $event->getForm();
$this->addElements($form);
}
public function addElements(FormInterface $form){
$form
->add('name', TextType::class, ['label' => 'Nombre','attr' => ['class' =>'form-control']])
->add('email', EmailType::class, ['label' => 'Email','attr' => ['class' =>'form-control']])
->add('phone', TextType::class, ['label' => 'Teléfono de contacto','attr' => ['class' =>'form-control']]);
}
}