PHP code example of acseo / dynamic-form-bundle
1. Go to this page and download the library: Download acseo/dynamic-form-bundle 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' );
acseo / dynamic-form-bundle example snippets php
public function registerBundles ()
{
$bundles = array (
new ACSEO\Bundle\DynamicFormBundle\ACSEODynamicFormBundle(),
);
}
php
public function indexAction ()
{
$formArray = array (
'name' => array (
'type' => 'text' ,
'options' => array (
'label' => 'Nom' ,
'help' => 'Renseignez votre nom' ,
'picto' => 'text' ,
),
'constraints' => array (
'NotBlank' => true ,
'Length' => array ('min' => 2 ),
)
),
'amount' => array (
'type' => 'money' ,
'options' => array (
'label' => 'Montant TTC' ,
'help' => 'Montant total de votre achat' ,
'picto' => 'money' ,
),
'constraints' => array (
'NotBlank' => true
)
),
'buydate' => array (
'type' => 'date' ,
'options' => array (
'label' => "Date d'achat" ,
'picto' => 'date' ,
),
'constraints' => array (
'NotBlank' => true
)
),
'product' => array (
'type' => 'text' ,
'options' => array (
'label' => 'Libellé produit' ,
'picto' => 'text' ,
'help' => 'lorem ipsum' ,
'data' => array (
array ('value' => 'Foo' ),
array ('value' => 'Bar' )
)
),
'constraints' => array (
'NotBlank' => true
),
'multiple' => true
),
);
$arrayFormProvider = $this ->get('acseo.form.array.provider' );
$arrayFormProvider->setFormArray($formArray);
$form = $this ->get('acseo.form.manager' )->createForm($arrayFormProvider);
if ($this ->container->get('request' )->isMethod('POST' )) {
$form->handleRequest($this ->container->get('request' ));
if ($form->isValid()) {
$data = $form->getData();
}
}
return array ('form' => $form->createView());
}