PHP code example of atournayre / form
1. Go to this page and download the library: Download atournayre/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/ */
atournayre / form example snippets
namespace App\Subscriber\Form;
use Atournayre\Helper\Decorator\Form\MaxLengthFormDecorator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class FormDecoratorSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
FormEvents::PRE_SET_DATA => 'onPreSetData',
];
}
public function onPreSetData(FormEvent $event)
{
$form = $event->getForm();
// Add a maxlength attribute to all text fields.
MaxLengthFormDecorator::decorate($form);
}
}