PHP code example of wandi / ordered-form

1. Go to this page and download the library: Download wandi/ordered-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/ */

    

wandi / ordered-form example snippets


namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class YourController extends AbstractController
{
    // [...]
    
    public function __construct(/* DI */)
    {
        // [...]
    }
    
    public function yourAction(Request $request): Response
    {
        $yourEntity = new Entity();
        
        $form = $this->createForm(YourType::class, $yourEntity, [
            // your options
        ]);
        $form->handleRequest($request);
        
         // [...]
    }
}

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\FormExtensionInterface;
use Ivory\OrderedForm\Extension\OrderedExtension;
use Symfony\Component\Form\Forms;
use Ivory\OrderedForm\OrderedResolvedFormTypeFactory;

class YourController extends AbstractController
{
    /**
     * @var FormExtensionInterface
     */
    private $formExtension;
    
    public function __construct(FormExtensionInterface $formExtension)
    {
        $this->formExtension = $formExtension;
    }
    
    public function yourAction(Request $request): Response
    {
        $yourEntity = new Entity();
        
        $formFactory = Forms::createFormFactoryBuilder()
            ->setResolvedTypeFactory(new OrderedResolvedFormTypeFactory())
            ->addExtension($this->formExtension)
            ->addExtension(new OrderedExtension())
            ->getFormFactory();
        $form = $formFactory->create(YourType::class, $yourEntity, [
            // your options
        ]);
        $form->handleRequest($request);
        
         // [...]
    }
}