Created
February 1, 2013 10:54
-
-
Save bakura10/4690641 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 | |
namespace User\Form\Student; | |
use Zend\Form\Form; | |
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator; | |
class EditSkills extends Form | |
{ | |
public function __construct() | |
{ | |
parent::__construct('edit-skills-form'); | |
$this->setHydrator(new ClassMethodsHydrator(false)); | |
$this->add(array( | |
'type' => 'User\Form\Student', | |
'name' => 'student', | |
'options' => array( | |
'use_as_base_fieldset' => true | |
) | |
)); | |
// Add the skills | |
$this->get('student')->add(array( | |
'type' => 'Zend\Form\Element\Collection', | |
'name' => 'skills', | |
'options' => array( | |
'count' => 1, | |
'allow_add' => true, | |
'allow_remove' => true, | |
'should_create_template' => true, | |
'target_element' => array( | |
'type' => 'User\Form\StudentSkill' | |
) | |
) | |
)); | |
$this->add(array( | |
'type' => 'Zend\Form\Element\Submit', | |
'name' => 'submit', | |
'attributes' => array( | |
'value' => 'Sauvegarder', | |
'class' => 'button button-blue' | |
) | |
)); | |
$this->setValidationGroup(array( | |
'student' => array( | |
'skills' | |
) | |
)); | |
} | |
} |
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 | |
namespace User\Form; | |
use Common\Registry\Registry; | |
use DoctrineORMModule\Stdlib\Hydrator\DoctrineEntity as DoctrineHydrator; | |
use User\Entity\StudentSkill as StudentSkillEntity; | |
use Zend\Form\Fieldset; | |
use Zend\InputFilter\InputFilterProviderInterface; | |
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator; | |
class StudentSkill extends Fieldset implements InputFilterProviderInterface | |
{ | |
/** | |
* Constructor | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->setHydrator(new DoctrineHydrator(Registry::get('EntityManager'))) | |
->setObject(new StudentSkillEntity()); | |
$this->add(array( | |
'name' => 'id', | |
'attributes' => array( | |
'type' => 'hidden' | |
) | |
)); | |
$this->add(array( | |
'name' => 'name', | |
'attributes' => array( | |
'type' => 'text', | |
'maxlength' => 32, | |
'style' => 'width: 44.8%' | |
) | |
)); | |
$this->add(array( | |
'type' => 'Zend\Form\Element\Select', | |
'name' => 'level', | |
'options' => array( | |
'value_options' => array( | |
25 => 'Débutant', | |
50 => 'Intermédiaire', | |
75 => 'Confirmé', | |
100 => 'Expert' | |
) | |
), | |
'attributes' => array( | |
'style' => 'width: 47%', | |
'value' => 25, | |
'class' => 'last' | |
) | |
)); | |
} | |
/** | |
* @return array | |
*/ | |
public function getInputFilterSpecification() | |
{ | |
return array( | |
'id' => array( | |
'required' => true, | |
'allow_empty' => true | |
), | |
'name' => array( | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags') | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array('max' => 32) | |
) | |
) | |
), | |
'level' => array( | |
'required' => true | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment