new: usr: add Contact page with email sending behaviour #4
All checks were successful
Deploy to Production / deploy (push) Successful in 39s
All checks were successful
Deploy to Production / deploy (push) Successful in 39s
This commit is contained in:
89
src/Form/ContactFormType.php
Normal file
89
src/Form/ContactFormType.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\ContactMessage;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
/**
|
||||
* Class ContactFormType
|
||||
*
|
||||
* @package App\Form
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 15.
|
||||
*/
|
||||
class ContactFormType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('name', TextType::class, [
|
||||
'label' => 'Name',
|
||||
'constraints' => [
|
||||
new NotBlank(message: 'Please enter your name.'),
|
||||
new Length(
|
||||
min: 2,
|
||||
max: 255,
|
||||
minMessage: 'Name must be at least {{ limit }} characters.',
|
||||
maxMessage: 'Name cannot be longer than {{ limit }} characters.',
|
||||
),
|
||||
],
|
||||
])
|
||||
->add('email', EmailType::class, [
|
||||
'label' => 'Email',
|
||||
'constraints' => [
|
||||
new NotBlank(message: 'Please enter your email address.'),
|
||||
new Email(message: 'Please enter a valid email address.'),
|
||||
],
|
||||
])
|
||||
->add('content', TextareaType::class, [
|
||||
'label' => 'Message',
|
||||
'constraints' => [
|
||||
new NotBlank(message: 'Please enter your message.'),
|
||||
new Length(
|
||||
min: 10,
|
||||
max: 5000,
|
||||
minMessage: 'Message must be at least {{ limit }} characters.',
|
||||
maxMessage: 'Message cannot be longer than {{ limit }} characters.',
|
||||
),
|
||||
],
|
||||
])
|
||||
->add('consent', CheckboxType::class, [
|
||||
'label' => 'I have read the Privacy and Data Processing Policy and I consent to the processing of my data.',
|
||||
'mapped' => true,
|
||||
'constraints' => [
|
||||
new IsTrue(message: 'You must agree to the privacy policy to submit this form.'),
|
||||
],
|
||||
])
|
||||
->add('recaptcha', RecaptchaType::class);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => ContactMessage::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user