Skip to content
Snippets Groups Projects
user-create-form.php 13 KiB
Newer Older
<?php
/**
 * Copyright (C) 2019 Leipzig University Library
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * @author  Sebastian Kehr <kehr@ub.uni-leipzig.de>
 * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
 */

use fid\Hydrator\UserHydrator;
use fid\InputFilter\RootAwareBaseInputFilter;
use fid\InputFilter\UserCreateFormInputFilter;
use Zend\Filter\Boolean;
use Zend\Filter\StringTrim;
use Zend\Form\Element\Checkbox;
use Zend\Form\Element\Password;
use Zend\Form\Element\Radio;
use Zend\Form\Element\Select;
use Zend\Form\Element\Submit;
use Zend\Form\Element\Text;
use Zend\Form\InputFilterProviderFieldset;
use Zend\Validator\EmailAddress;
use Zend\Validator\Identical;
use Zend\Validator\NotEmpty;
use Zend\Validator\Regex;
use Zend\Validator\StringLength;

return [
    'name'         => 'user-create-form',
    'hydrator'     => UserHydrator::class,
            'spec' => [
                'name'       => 'username',
                'type'       => Text::class,
                'options'    => [
                    'label' => 'label_username',
                ],
                'attributes' => [
            'spec' => [
                'name'       => 'password',
                'type'       => Password::class,
                'options'    => [
                    'label' => 'label_password',
                ],
                'attributes' => [
        'password_confirmation' => [
                'name'       => 'password_confirmation',
                'type'       => Password::class,
                'options'    => [
                    'label' => 'label_password_confirmation',
                ],
                'attributes' => [
            'spec' => [
                'name'    => 'salutation',
                'type'    => Select::class,
                'options' => [
                    'label'        => 'label_salutation',
                    'options'      => [
                        'mr'  => [
                            'value' => 'mr',
                            'label' => 'label_salutation_mr',
                        ],
                        'mrs' => [
                            'value' => 'mrs',
                            'label' => 'label_salutation_mrs',
                'name'    => 'academic_title',
                'type'    => Text::class,
                'options' => [
                    'label' => 'label_academic_title',
                ],
            ],
        ],
            'spec' => [
                'name'       => 'firstname',
                'type'       => Text::class,
                'options'    => [
                    'label' => 'label_firstname',
                ],
                'attributes' => [
            'spec' => [
                'name'       => 'lastname',
                'type'       => Text::class,
                'options'    => [
                    'label' => 'label_lastname',
                ],
                'attributes' => [
                'name'       => 'home_library',
                'type'       => Select::class,
                'options'    => [
                    'label'        => 'label_home_library',
                    'empty_option' => '',
                ],
                'attributes' => [
                'type'       => Radio::class,
                'options'    => [
                    'label'         => 'label_job_title',
                    'value_options' => [
                        'job_title_0',
                        'job_title_1'
                    ],
            'spec' => [
                'name'    => 'college',
                'type'    => Text::class,
                'options' => [
                    'label' => 'label_college',
        'addresses'             => require 'address-collection.php',
        'data'                  => [
                'name' => 'data',
                'type' => InputFilterProviderFieldset::class,
                'name'       => 'eula_accepted',
                'type'       => Checkbox::class,
                'attributes' => [
            'spec' => [
                'name'       => 'submit',
                'type'       => Submit::class,
                'attributes' => [
                    'value' => 'label_submit',
                ],
            ],
        ],
    ],
    'input_filter' => [
        'type'                  => UserCreateFormInputFilter::class,
            'name'       => 'username',
            'filters'    => [
                StringTrim::class => [
                    'name' => StringTrim::class,
                ],
            ],
            'validators' => [
                StringLength::class => [
                    'name'    => StringLength::class,
                    'options' => [
                        'max' => 255
                    ],
                ],
                EmailAddress::class => [
                    'name' => EmailAddress::class,
                ],
            ],
        ],
            'name'       => 'password',
            'filters'    => [
                StringTrim::class => [
                    'name' => StringTrim::class,
                ],
            ],
            'validators' => [
                StringLength::class => [
                    'name'    => StringLength::class,
                    'options' => [
                        'min'      => 8,
                        'max'      => 255,
                        'messages' => [
                            StringLength::TOO_SHORT => 'error_password_length',
                            StringLength::TOO_LONG  => 'error_password_length',
                        ],
                    ],
                ],
                Regex::class        => [
                    'name'    => Regex::class,
                    'options' => [
                        'pattern'  => '/(?:.*[0-9].*[^\w].*|.*[^\w].*[0-9].*)/',
                        'messages' => [
                            Regex::NOT_MATCH => 'error_password_pattern',
                        ],
                    ],
                ],
            ],
        ],
        'password_confirmation' => [
            'name'       => 'password_confirmation',
            'validators' => [
                NotEmpty::class  => [
                    'name' => NotEmpty::class,
                ],
                Identical::class => [
                    'name'    => Identical::class,
                    'options' => [
                        'strict'   => false,
                        'messages' => [
                            Identical::NOT_SAME => 'error_password_confirmation',
                        ],
                    ],
                ],
            ],
        ],
            'name'     => 'salutation',
            'required' => false,
            'filters'  => [
                StringTrim::class => [
                    'name' => StringTrim::class,
                ],
            ],
        ],
        'academic_title'        => [
            'name'       => 'academic_title',
            'required'   => false,
            'filters'    => [
                StringTrim::class => [
                    'name' => StringTrim::class,
                ],
            ],
            'validators' => [
                StringLength::class => [
                    'name'    => StringLength::class,
                    'options' => [
                        'max' => 255
            'name'       => 'firstname',
            'required'   => true,
            'filters'    => [
                StringTrim::class => [
                    'name' => StringTrim::class,
                ],
            ],
            'validators' => [
                StringLength::class => [
                    'name'    => StringLength::class,
                    'options' => [
                        'max' => 255
                    ],
                ],
                Regex::class        => [
                    'name'    => Regex::class,
                    'options' => [
                        'pattern' => '/^\D*$/',
                    ],
                ],
            ],
        ],
            'name'       => 'lastname',
            'required'   => true,
            'filters'    => [
                StringTrim::class => [
                    'name' => StringTrim::class,
                ],
            ],
            'validators' => [
                StringLength::class => [
                    'name'    => StringLength::class,
                    'options' => [
                        'max' => 255
                ],
                Regex::class        => [
                    'name'    => Regex::class,
                    'options' => [
                        'pattern' => '/^\D*$/',
                    ],
                ],
            ],
        ],
        'home_library'          => [
            'name'       => 'home_library',
            'required'   => true,
            'filters'    => [
                StringTrim::class => [
                    'name' => StringTrim::class,
                ],
            ],
            'validators' => [
                StringLength::class => [
                    'name'    => StringLength::class,
                    'options' => [
                        'max' => 255
        'job_title'             => [
            'name'     => 'job_title',
            'required' => true,
        'college'               => [
            'name'       => 'college',
            'required'   => false,
            'filters'    => [
                StringTrim::class => [
                    'name' => StringTrim::class,
                ],
            ],
            'validators' => [
                StringLength::class => [
                    'name'    => StringLength::class,
                    'options' => [
                        'max' => 255
                    ],
                ],
            ],
        'eula_accepted'         => [
            'name'       => 'eula_accepted',
            'required'   => true,
            'filters'    => [
                Boolean::class => [
                    'name' => Boolean::class,
                ],
            ],
            'validators' => [
                NotEmpty::class => [
                    'name'    => NotEmpty::class,
                    'options' => [
                        'messages' => [
                            NotEmpty::IS_EMPTY => 'error_eula_accepted',
                        ],
                    ],
                ],
            ],
        ],
            'name'     => 'submit',
            'required' => true,
        ],
    ],