Skip to content

Instantly share code, notes, and snippets.

@gilsonbp
Created August 9, 2013 21:11
Show Gist options
  • Save gilsonbp/6197233 to your computer and use it in GitHub Desktop.
Save gilsonbp/6197233 to your computer and use it in GitHub Desktop.
Zend Form 1.12 usando Twitter Bootstrap e Decorators.
<?php
class Forms_Usuario extends Zend_Form {
public function init() {
$this->setMethod('post');
$this->setAttribs(array(
'class' => 'form span9',
'name' => 'form_usuarios'
));
$nome = $this->createElement('text', 'nome', array(
'label' => 'Nome:',
'class' => 'span4',
'placeholder' => 'João dos Santos'))
->setRequired(true)
->setAttrib('required', '')
->addValidator('StringLength', false, array(4));
$this->addElement($nome);
$email = $this->createElement('text', 'email', array(
'label' => 'E-mail:',
'class' => 'span4',
'placeholder' => 'joao@anic.in'))
->addValidator('EmailAddress')
->setRequired(true)
->setAttrib('required', '')
->addValidator(new Zend_Validate_Db_NoRecordExists(
array(
'table' => 'hr001',
'field' => 'email',
)));
$this->addElement($email);
$login = $this->createElement('text', 'login', array(
'label' => 'Login:',
'class' => 'span4',
'placeholder' => 'joao'))
->setRequired(true)
->setAttrib('required', '')
->addValidator('StringLength', false, array('min' => 3, 'max' => 50))
->addValidator(new Zend_Validate_Db_NoRecordExists(
array(
'table' => 'hr001',
'field' => 'login',
)));
$this->addElement($login);
$senha = $this->createElement('password', 'senha', array(
'label' => 'Senha:',
'class' => 'span4',
'trim' => true,
'placeholder' => 'Senha de 3 a 15 caracteres'
))
->setRequired()
->setAttrib('required', '')
->addValidator('StringLength', false, array(3, 15));
$this->addElement($senha);
// grupos
$grupos = new Application_Model_DbTable_Grupo();
$grupo = $this->createElement('select', 'grupo_id', array(
'label' => 'Grupo:',
'class' => 'span4',
'MultiOptions' => $grupos->getPares()))
->setAttrib('required', '')
->setRequired(true);
$this->addElement($grupo);
$fone = $this->createElement('text', 'fone', array(
'label' => 'Fone:',
'class' => 'span4',
'placeholder' => '(00)0000-0000'))
->addValidator('StringLength', false, array(10))
->setRequired(true)
->setAttrib('required', '');
$this->addElement($fone);
$ativo = $this->createElement('select', 'a', array(
'label' => 'Ativo:',
'class' => 'span1',
'MultiOptions' => array('Y' => 'SIM', 'N' => 'NÃO')))
->setRequired(true)
->setAttrib('required', '');
$this->addElement($ativo);
$submit = $this->createElement('submit', 'Salvar', array(
'value' => 'Salvar',
'class' => 'btn btn-primary'));
$this->addElement($submit);
// Configurando os Decorators
$this->setElementDecorators(array('ViewHelper', 'Errors', 'Label'));
$this->setDecorators(array('FormElements', 'Form'));
// Setando os decorators de cada campo
$nome->setDecorators(array(
'ViewHelper',
'Errors',
'Description',
array(array('label' => 'label')),
array(array('class' => 'HtmlTag'), array('class' => 'span4'))
));
$email->setDecorators(array(
'ViewHelper',
'Errors',
'Description',
array(array('label' => 'label')),
array(array('class' => 'HtmlTag'), array('class' => 'span4'))
));
$login->setDecorators(array(
'ViewHelper',
'Errors',
'Description',
array(array('label' => 'label')),
array(array('class' => 'HtmlTag'), array('class' => 'span4'))
));
$senha->setDecorators(array(
'ViewHelper',
'Errors',
'Description',
array(array('label' => 'label')),
array(array('class' => 'HtmlTag'), array('class' => 'span4'))
));
$grupo->setDecorators(array(
'ViewHelper',
'Errors',
'Description',
array(array('label' => 'label')),
array(array('class' => 'HtmlTag'), array('class' => 'span4'))
));
$fone->setDecorators(array(
'ViewHelper',
'Errors',
'Description',
array(array('label' => 'label')),
array(array('class' => 'HtmlTag'), array('class' => 'span4'))
));
$ativo->setDecorators(array(
'ViewHelper',
'Errors',
'Description',
array(array('label' => 'label')),
array(array('class' => 'HtmlTag'), array('class' => 'span4'))
));
$submit->setDecorators(array(
'ViewHelper',
array(array('class' => 'HtmlTag'), array('class' => 'actions span8'))
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment