1. Go to this page and download the library: Download lin3s/wp-symfony-form library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lin3s / wp-symfony-form example snippets
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\Validator\Constraints;
class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'constraints' => new Constraints\NotBlank(),
'label' => 'Name',
])
->add('surname', TextType::class, [
'constraints' => new Constraints\NotBlank(),
'label' => 'Surname',
])
->add('phone', TextType::class, [
'constraints' => new Constraints\NotBlank(),
'label' => 'Phone',
])
->add('email', EmailType::class, [
'constraints' => new Constraints\Email(),
'label' => 'Email',
])
->add('message', TextareaType::class, [
'constraints' => new Constraints\NotBlank(),
'label' => 'Message',
])
->add('conditions', CheckboxType::class, [
'mapped' => false,
]);
}
}
js
WPSymfonyForm.onSuccess(function ($form) {
if ($form.hasClass('form--contact')) {
// ANYTHING YOU WANT TO DO
}
$form.find('.form__footer').html('<p>Form successfully submitted</p>');
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.