Esempio n. 1
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $what = new \Zend\Form\Element\Radio('What');
     $what->setValueOptions(array(\Model\Client\Client::MEMBERSHIP_AUTOMATIC => $this->_('Store search parameters. Group memberships will be updated automatically.'), \Model\Client\Client::MEMBERSHIP_ALWAYS => $this->_('Add current search results. Group memberships will be set only this time.'), \Model\Client\Client::MEMBERSHIP_NEVER => $this->_('Exclude search results from a group.')));
     $what->setValue(\Model\Client\Client::MEMBERSHIP_AUTOMATIC);
     $this->add($what);
     $where = new \Zend\Form\Element\Radio('Where');
     $where->setValueOptions(array('new' => $this->_('Store in new group'), 'existing' => $this->_('Store in existing group')));
     $where->setValue('new')->setAttribute('onchange', 'selectElements()');
     $this->add($where);
     $newGroup = new \Zend\Form\Element\Text('NewGroup');
     $newGroup->setLabel('Name');
     $this->add($newGroup);
     $description = new \Zend\Form\Element\Text('Description');
     $description->setLabel('Description');
     $this->add($description);
     $existingGroup = new \Library\Form\Element\SelectSimple('ExistingGroup');
     $existingGroup->setLabel('Group');
     $groups = array();
     foreach ($this->getOption('GroupManager')->getGroups(null, null, 'Name') as $group) {
         $groups[] = $group['Name'];
     }
     $existingGroup->setValueOptions($groups);
     $this->add($existingGroup);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'NewGroup', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(1, 255), 'message' => "Value is required and can't be empty"), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateGroupExists'), 'message' => $this->_('The name already exists'))))));
     $inputFilter->add(array('name' => 'Description', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null', 'options' => array('type' => 'string'))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long'))))));
     $this->setInputFilter($inputFilter);
 }
Esempio n. 2
0
 public function __construct($name = null)
 {
     // we want to ignore the name passed
     parent::__construct('demo2');
     $this->setAttribute('method', 'post');
     $this->add(array('name' => 'genre', 'type' => 'Zend\\Form\\Element\\Select', 'options' => array('label' => 'Genre', 'value_options' => array('Alternative', 'Country', 'Jazz', 'Rap', 'Rock'))));
     $this->add(array('name' => 'club', 'type' => 'Zend\\Form\\Element\\MultiCheckbox', 'options' => array('label' => 'Club', 'value_options' => array('Vitesse', 'Ajax', 'Feyenoord'))));
     $check = new \Zend\Form\Element\Checkbox('check', array('label' => 'Checkbox'));
     $this->add($check);
     $radio = new \Zend\Form\Element\Radio('radio', array('label' => 'Radio'));
     $radio->setValueOptions(array('One', 'Two', 'Three'));
     $this->add($radio);
     $text = new \Zend\Form\Element\Text('text', array('label' => 'Text'));
     $this->add($text);
     $this->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Go', 'id' => 'submitbutton')));
     $inputFilters = new InputFilter();
     $inputFilters->add(array('name' => 'genre', 'required' => true, 'allowEmpty' => false));
     $inputFilters->add(array('name' => 'club', 'required' => true, 'allowEmpty' => true));
     $inputFilters->add(array('name' => 'radio', 'required' => true));
     $this->setInputFilter($inputFilters);
 }
 /**
  * Set available groups
  *
  * The "Groups" fieldset is (re)created with radio buttons for each group.
  *
  * @param string[] $groups Group names
  */
 public function setGroups(array $groups)
 {
     if ($this->has('Groups')) {
         $this->remove('Groups');
     }
     $fieldset = new \Zend\Form\Fieldset('Groups');
     $this->add($fieldset);
     $buttons = array(\Model\Client\Client::MEMBERSHIP_AUTOMATIC => $this->_('automatic'), \Model\Client\Client::MEMBERSHIP_ALWAYS => $this->_('always'), \Model\Client\Client::MEMBERSHIP_NEVER => $this->_('never'));
     foreach ($groups as $group) {
         $element = new \Zend\Form\Element\Radio($group);
         $element->setLabel($group);
         $element->setValueOptions($buttons);
         $element->setValue(\Model\Client\Client::MEMBERSHIP_AUTOMATIC);
         $fieldset->add($element);
     }
 }