예제 #1
0
 public function __construct(ObjectManager $objectManager)
 {
     parent::__construct('register');
     $this->filter = new InputFilter();
     $primary = new Element\Hidden('primary');
     $this->add($primary);
     $callName = new Element\Text('callName');
     $callName->setAttribute('required', true);
     $callName->setAttribute('placeholder', 'Call Name');
     $this->add($callName);
     $callNameFilter = new Input('callName');
     $callNameFilter->setRequired(true);
     $callNameFilter->getFilterChain()->attach(new AppFilter\TitleCase());
     $callNameFilter->getFilterChain()->attach(new Filter\StringTrim());
     $callNameFilter->getFilterChain()->attach(new Filter\StripTags());
     $callNameFilter->getValidatorChain()->attach(new Validator\StringLength(array('max' => 15)));
     $callNameFilter->getValidatorChain()->attach(new LocaleValidator\Alpha(array('allowWhiteSpace' => true)));
     $this->filter->add($callNameFilter);
     $regName = new Element\Text('regName');
     $regName->setAttribute('placeholder', 'Registered Name');
     $this->add($regName);
     $regNameFilter = new Input('regName');
     $regNameFilter->setRequired(false);
     $regNameFilter->getFilterChain()->attach(new AppFilter\TitleCase());
     $regNameFilter->getFilterChain()->attach(new Filter\StringTrim());
     $regNameFilter->getFilterChain()->attach(new Filter\StripTags());
     $regNameFilter->getValidatorChain()->attach(new Validator\StringLength(array('max' => 50)));
     $regNameFilter->getValidatorChain()->attach(new Validator\Regex("/^[a-z][a-z\\'\\- ]*\$/i"));
     $this->filter->add($regNameFilter);
     $sex = new Element\Select('sex');
     $sex->setAttribute('required', true);
     $sex->setValueOptions(array(1 => 'Male', 2 => 'Female'));
     $sex->setEmptyOption('Select a Sex');
     $this->add($sex);
     $sexFilter = new Input('sex');
     $sexFilter->setRequired(true);
     $this->filter->add($sexFilter);
     $breed = new AppElement\ObjectLiveSearch('breed');
     $breed->setOption('object_manager', $objectManager);
     $breed->setOption('target_class', 'Application\\Entity\\Breed');
     $breed->setOption('find_method', array('name' => 'findBy', 'params' => array('criteria' => array(), 'orderBy' => array('name' => 'ASC'))));
     $breed->setEmptyOption('Select a Breed');
     $this->add($breed);
     $breedFilter = new Input('breed');
     $breedFilter->setRequired(true);
     $this->filter->add($breedFilter);
     $dateOfBirth = new Element\Date('dateOfBirth');
     $dateOfBirth->setAttribute('required', true);
     $dateOfBirth->setAttribute('data-placeholder', 'Date of Birth');
     // placeholder attr is invalid for date input
     $dateOfBirth->setAttribute('data-mask', '0000-00-00');
     $dateOfBirth->setAttribute('class', 'datepicker');
     $this->add($dateOfBirth);
     $dateOfBirthFilter = new Input('dateOfBirth');
     $dateOfBirthFilter->setRequired(true);
     $dateOfBirthFilter->getValidatorChain()->attach(new Validator\Date());
     $this->filter->add($dateOfBirthFilter);
     $height = new Element\Number('height');
     $height->setAttribute('required', true);
     $height->setAttribute('placeholder', 'Height (Inches)');
     $this->add($height);
     $heightFilter = new Input('height');
     $heightFilter->setRequired(true);
     $heightFilter->getValidatorChain()->attach(new Validator\Between(array('min' => 6, 'max' => 30)));
     $this->filter->add($heightFilter);
     $champion = new Element\Checkbox('champion');
     $champion->setLabel('Dog is a champion of record.');
     $this->add($champion);
     $championFilter = new Input('champion');
     $championFilter->setRequired(false);
     $this->filter->add($championFilter);
     $rescue = new Element\Checkbox('rescue');
     $rescue->setLabel('Dog is a rescue.');
     $this->add($rescue);
     $rescueFilter = new Input('rescue');
     $rescueFilter->setRequired(false);
     $this->filter->add($rescueFilter);
     $buttons = new Form('buttons');
     $buttons->setOption('twb-layout', 'inline');
     $buttons->setAttribute('class', 'form-group');
     $submit = new Element\Submit('submit');
     $submit->setAttribute('class', 'btn-primary pull-right');
     $submit->setOption('glyphicon', 'circle-arrow-up');
     $submit->setLabel('Register');
     $buttons->add($submit);
     $cancel = new Element\Submit('cancel');
     $cancel->setAttribute('formnovalidate', true);
     $cancel->setAttribute('class', 'btn-warning pull-right');
     $cancel->setOption('glyphicon', 'ban-circle');
     $cancel->setLabel('Cancel');
     $buttons->add($cancel);
     $this->add($buttons);
 }
예제 #2
0
 public function buildForm()
 {
     $this->setAttributes(array('id' => 'post-form', 'method' => 'post'));
     $category = new Element\Select('category');
     $category->setLabel('Categoria');
     $category->setValueOptions(array_combine($this->categories, $this->categories));
     $category->setAttribute('class', 'form-control');
     $title = new Element\Text('title');
     $title->setLabel('Título');
     $title->setAttributes(array('maxlength' => 128, 'class' => 'form-control'));
     $description = new Element\Textarea('description');
     $description->setAttribute('class', 'form-control');
     $description->setLabel('Descrição');
     $photoFilename = new Element\Url('photo_filename');
     $photoFilename->setAttribute('class', 'form-control');
     $photoFilename->setLabel('Foto');
     $contactName = new Element\Text('contact_name');
     $contactName->setAttribute('class', 'form-control');
     $contactName->setLabel('Nome completo');
     $contactEmail = new Element\Email('contact_email');
     $contactEmail->setAttribute('class', 'form-control');
     $contactEmail->setLabel('E-mail');
     $contactPhone = new Element\Text('contact_phone');
     $contactPhone->setAttribute('class', 'form-control');
     $contactPhone->setLabel('Contato');
     $cityCode = new Element\Select('cityCode');
     $cityCode->setAttribute('class', 'form-control');
     $cityCode->setValueOptions($this->cities);
     $cityCode->setLabel('Cidade');
     $deleteCode = new Element\Number('delete_code');
     $deleteCode->setAttribute('class', 'form-control');
     $deleteCode->setLabel('Código de deleção');
     $captcha = new Element\Captcha('captcha');
     $captchaAdapter = new ImageCaptcha(array('font' => './public/fonts/arial.ttf', 'imgDir' => './public/img/captcha', 'imgUrl' => '/img/captcha'));
     $captchaAdapter->setWordlen(4);
     $captcha->setCaptcha($captchaAdapter)->setLabel('Você é um ser humano ou um robô?')->setAttribute('class', 'captchaStyle')->setAttribute('title', 'Você é um ser humano ou um robô?');
     /*$captcha = new Element\Captcha('captcha');
             $captcha->setCaptcha(new \Zend\Captcha\Dumb());
             $captcha->setAttribute('class', 'form-control');
             $captcha->setOptions(array('label' => 'Você é um ser humano ou um robô?'));
     */
     $price = new Element\Number('price');
     $price->setAttributes(array('class' => 'form-control', 'maxlength' => 12, 'min' => 0, 'max' => '999999999999'));
     $price->setLabel('Preço');
     $dateExpires = new Element\Radio('date_expires');
     $dateExpires->setLabel('Expira em (dias)');
     $dateExpires->setValueOptions(array_combine($this->dateExpires, $this->dateExpires));
     $csrf = new Element\Csrf('security');
     $submit = new Element\Submit('submit');
     $submit->setAttributes(array('class' => 'btn btn-default', 'value' => 'Enviar formulário'));
     $this->add($category)->add($title)->add($price)->add($dateExpires)->add($description)->add($photoFilename)->add($contactName)->add($contactEmail)->add($contactPhone)->add($cityCode)->add($deleteCode)->add($captcha)->add($csrf)->add($submit);
     /*
             $factory = new \Zend\Form\Factory();
             $factory->createForm(array(
                 'hydrator' => 'Zend\Stdlib\Hydrator\ArraySerializable',
                 'elements' => array(
                     array(
                         'name' => 'category',
                         'type' => 'text',
                         'options' => array(
                             'label' => 'Category'
                         )
                     ),
                     array(
                         'name' => 'title',
                         'type' => 'text',
                         'options' => array(
                             'label' => 'Title'
                         )
                     ),
                 )
             )); */
 }