Skip to content

Instantly share code, notes, and snippets.

@bakura10
Created February 1, 2013 10:54
Show Gist options
  • Save bakura10/4690641 to your computer and use it in GitHub Desktop.
Save bakura10/4690641 to your computer and use it in GitHub Desktop.
<?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'
)
));
}
}
<?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