Created
July 19, 2012 14:50
-
-
Save awartoft/3144467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Antoine Hedgecock <[email protected]> | |
*/ | |
/** | |
* @namespace | |
*/ | |
namespace User\Form\Fieldsets; | |
use Zend\Form\Fieldset, | |
Zend\InputFilter\InputFilterProviderInterface; | |
use Zend\Validator, | |
Zend\I18n\Validator as I18nValidator; | |
class UserFieldset extends Fieldset implements InputFilterProviderInterface | |
{ | |
public function __construct() | |
{ | |
parent::__construct('user'); | |
$this->setObject(new \User\Entity\User()) | |
->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods()); | |
$this->add( | |
array( | |
'name' => 'first_name', | |
'options' => array( | |
'label' => 'Förnamn', | |
), | |
'attributes' => array( | |
'required' => 'required' | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'last_name', | |
'options' => array( | |
'label' => 'Efternamn', | |
), | |
'attributes' => array( | |
'required' => 'required' | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'gender', | |
'options' => array( | |
'label' => 'Kön', | |
), | |
'attributes' => array( | |
'options' => array( | |
'm' => 'Man', | |
'f' => 'Kvinna' | |
) | |
), | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'password', | |
'options' => array( | |
'label' => 'Lösenord', | |
), | |
'attributes' => array( | |
'type' => 'password', | |
'required' => 'required' | |
), | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'password-repeat', | |
'options' => array( | |
'label' => 'Lösenord igen', | |
), | |
'attributes' => array( | |
'type' => 'password', | |
'required' => 'required' | |
), | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'telephone', | |
'options' => array( | |
'label' => 'Telefon', | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'email', | |
'options' => array( | |
'label' => 'Email' | |
), | |
'attributes' => array( | |
'required' => 'required' | |
), | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'username', | |
'options' => array( | |
'label' => 'Användarnamn' | |
), | |
'attributes' => array( | |
'required' => 'required' | |
), | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'birthday', | |
'options' => array( | |
'label' => 'Födelsedag', | |
), | |
'attributes' => array( | |
'id' => 'birthday' | |
), | |
'attributes' => array( | |
'required' => 'required' | |
), | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'submit', | |
'attributes' => array( | |
'id' => 'submit', | |
'type' => 'submit', | |
'value' => 'Registrera', | |
), | |
) | |
); | |
} | |
/** | |
* Should return an array specification compatible with | |
* {@link Zend\InputFilter\Factory::createInputFilter()}. | |
* | |
* @return array | |
*/ | |
public function getInputFilterSpecification() | |
{ | |
return array( | |
'first_name' => array( | |
'required' => true, | |
'validators' => array( | |
array( | |
'name' => 'NotEmpty', | |
'breakChainOnFailure' => true, | |
'options' => array( | |
'messages' => array( | |
Validator\NotEmpty::IS_EMPTY => 'Du har inte angivit ditt förnamn.' | |
) | |
) | |
), | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'min' => 2, | |
'max' => 20, | |
'messages' => array( | |
Validator\StringLength::TOO_SHORT => 'Förnamnet är för kort.', | |
Validator\StringLength::TOO_LONG => 'Förnamnet är för långt. Får max bestå av tjugo tecken.', | |
) | |
), | |
), | |
) | |
), | |
'last_name' => array( | |
'required' => true, | |
'validators' => array( | |
array( | |
'name' => 'NotEmpty', | |
'breakChainOnFailure' => true, | |
'options' => array( | |
'messages' => array( | |
Validator\NotEmpty::IS_EMPTY => 'Du har inte angivit ditt efternamn.' | |
) | |
) | |
), | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'min' => 2, | |
'max' => 25, | |
'messages' => array( | |
Validator\StringLength::TOO_SHORT => 'Efternamnet är för kort.', | |
Validator\StringLength::TOO_LONG => 'Efternamnet är för långt. Får max bestå av tjugofem tecken.' | |
) | |
), | |
), | |
) | |
), | |
'gender' => array( | |
'required' => true | |
), | |
'password' => array( | |
'required' => true, | |
'validators' => array( | |
array( | |
'name' => 'NotEmpty', | |
'breakChainOnFailure' => true, | |
'options' => array( | |
'messages' => array( | |
Validator\NotEmpty::IS_EMPTY => 'Du har inte angivit ett lösenord' | |
) | |
) | |
), | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'min' => 6, | |
'messages' => array( | |
Validator\StringLength::TOO_SHORT => 'Lösenordet du angivit är för kort. Måste vara fler än 6st bokstäver' | |
) | |
), | |
), | |
) | |
), | |
'password-repeat' => array( | |
'required' => true, | |
'allow_empty' => true, | |
'validators' => array( | |
array( | |
'name' => 'Identical', | |
'options' => array( | |
'token' => 'password', | |
'messages' => array( | |
Validator\Identical::NOT_SAME => 'Lösenorden du angav matchade inte.' | |
) | |
) | |
) | |
) | |
), | |
'telephone' => array( | |
'required' => true, | |
'allow_empty' => true | |
), | |
'email' => array( | |
'required' => true, | |
'validators' => array( | |
array( | |
'name' => 'NotEmpty', | |
'breakChainOnFailure' => true, | |
'options' => array( | |
'type' => Validator\NotEmpty::STRING, | |
'messages' => array( | |
Validator\NotEmpty::IS_EMPTY => 'Du måste ange din e-post.' | |
) | |
) | |
), | |
array( | |
'name' => 'EmailAddress', | |
'options' => array( | |
'messages' => array( | |
Validator\EmailAddress::INVALID => 'Epost adressen du angav är ogiltig', | |
) | |
) | |
) | |
) | |
), | |
'username' => array( | |
'required' => true, | |
'validators' => array( | |
array( | |
'name' => 'NotEmpty', | |
'breakChainOnFailure' => true, | |
'options' => array( | |
'type' => Validator\NotEmpty::STRING, | |
'messages' => array( | |
Validator\NotEmpty::IS_EMPTY => 'Du har inte angivit ett användarnamn.' | |
) | |
) | |
), | |
array( | |
'name' => 'Regex', | |
'options' => array( | |
'pattern' => '/^[a-z0-9_\.-]+$/i', | |
'messages' => array( | |
Validator\Regex::NOT_MATCH => 'Ditt användarnamn får bara bestå av bokstäver, siffror, punkt. ' | |
) | |
) | |
) | |
) | |
), | |
'birthday' => array( | |
'required' => true, | |
'validators' => array( | |
array( | |
'name' => 'date', | |
'options' => array( | |
'messages' => array( | |
Validator\Date::FALSEFORMAT => 'Ogiltigt födelsedatum angivet.', | |
Validator\Date::INVALID_DATE => 'Ogiltigt födelsedatum angivet.' | |
) | |
) | |
) | |
) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment