PHP code example of spotonlive / sl-laravel-zf2-form

1. Go to this page and download the library: Download spotonlive/sl-laravel-zf2-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/ */

    

spotonlive / sl-laravel-zf2-form example snippets


return [
    'aliases' => [
        'Form' => SpotOnLive\LaravelZf2Form\Facades\Helpers\FormHelperFacade::class,
    ]
];



namespace App\Forms\Customer;

use Zend\Form\Form;
use App\Entities\Country;
use App\Entities\Customer;
use Zend\Form\Element\Text;
use Zend\InputFilter\FileInput;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterInterface;
use DoctrineModule\Form\Element\ObjectSelect;
use Doctrine\Common\Persistence\ObjectManager;
use Zend\InputFilter\InputFilterAwareInterface;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;

class CreateForm extends Form
{
    /** @var ObjectManager */
    protected $objectManager;

    protected $inputFilter;

    public function __construct($name = null, ObjectManager $objectManager)
    {
        $this->objectManager = $objectManager;

        $this->setHydrator(new DoctrineHydrator($objectManager, Customer::class));
        $this->setObject(new Customer());

        parent::__construct('create-customer');

        $this->add([
            'name' => 'name',
            'type' => Text::class,
            'options' => [
                'label' => 'Name',
            ],
            'attributes' => [
                'class' => 'form-control',
                '['name' => 'StringTrim'],
                ],
                'validators' => [
                    [
                        'name'    => 'StringLength',
                        'options' => [
                            'encoding' => 'UTF-8',
                            'min'      => 1,
                            'max'      => 255,
                        ],
                    ],
                ],
            ]);

            $inputFilter->add([
                'name'     => 'country',
                '

@extends('layout')

@section('content')
    <h1>{{_('Form')}}</h1>

    {!! Form::openTag($form) !!}

    {!! csrf_field() !!}

    {!! Form::row($form->get('name')) !!}
    {!! Form::row($form->get('country')) !!}

    {!! Form::button($form->get('submit')) !!}

    {!! Form::closeTag() !!}
@endsection