Skip to content

Instantly share code, notes, and snippets.

@gpfiel
Created August 27, 2013 12:57
Show Gist options
  • Save gpfiel/6353174 to your computer and use it in GitHub Desktop.
Save gpfiel/6353174 to your computer and use it in GitHub Desktop.
Fieldset
<?php
namespace Admin\Form;
use Admin\Model\Banner;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
use Zend\Validator\NotEmpty;
use Zend\Validator\StringLength;
class BannerFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct()
{
parent::__construct('banner-form');
$this->setAttribute('method', 'post');
$this->setAttribute('enctype','multipart/form-data');
$this->setHydrator(new ClassMethodsHydrator(false))
->setObject(new Banner());
$this->setLabel('Banner');
$this->add(array(
'name' => 'cod_banner',
'attributes' => array(
'type' => 'hidden',
),
));
$this->add(array(
'name' => 'cod_banner_pai',
'attributes' => array(
'type' => 'hidden',
),
));
$this->add(array(
'name' => 'cod_idioma',
'attributes' => array(
'type' => 'hidden',
),
));
$this->add(array(
'name' => 'nom_banner',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Nome',
),
));
$this->add(array(
'name' => 'des_banner',
'attributes' => array(
'type' => 'textarea',
'class' => 'span6',
'style' => 'height:200px; resize:none;'
),
'options' => array(
'label' => 'Descrição',
),
));
$this->add(array(
'name' => 'url_imagem',
'attributes' => array(
'type' => 'file',
),
'options' => array(
'label' => 'Imagem',
),
));
$this->add(array(
'name' => 'url_banner',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Link',
),
));
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'ind_status',
'options' => array(
'label' => 'Situação',
'value_options' => array(
'2' => 'Inativo',
'1' => 'Ativo'
),
),
'attributes' => array(
'value' => '2'
)
));
}
public function getInputFilterSpecification()
{
return array(
'nom_banner' => array(
'required' => true,
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 250,
'messages' => array(
StringLength::TOO_SHORT => 'Deve conter no mínimo um caracter.',
StringLength::TOO_LONG => 'Não pode exceder 250 caracteres.',
),
)
),
array(
'name' => 'NotEmpty',
'options' => array(
'messages' => array(
NotEmpty::IS_EMPTY => 'Preenchimento obrigatório.',
),
),
),
),
'filters' => array(
array(
'name' => 'StripTags'
),
array(
'name' => 'StringTrim'
)
),
),
'cod_banner' => array(
'required' => false,
'filters' => array(
array(
'name' => 'Int'
)
)
),
'cod_banner_pai' => array(
'required' => false,
'filters' => array(
array(
'name' => 'Int'
)
)
),
'cod_idioma' => array(
'required' => false,
'filters' => array(
array(
'name' => 'Int'
)
)
),
'des_banner' => array(
'required' => false,
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8'
)
)
),
'filters' => array(
array(
'name' => 'StripTags'
),
array(
'name' => 'StringTrim'
)
),
),
'ind_status' => array(
'required' => false,
'filters' => array(
array(
'name' => 'Int'
)
)
),
'url_imagem' => array(
'required' => true,
'validators' => array(
array(
'name' => 'NotEmpty',
'options' => array(
'messages' => array(
NotEmpty::IS_EMPTY => 'É obrigatório a seleção de uma imagem.',
),
),
),
),
),
'url_banner' => array(
'required' => false,
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'max' => 250,
'messages' => array(
StringLength::TOO_LONG => 'Não pode exceder 250 caracteres.',
),
)
)
),
'filters' => array(
array(
'name' => 'StripTags'
),
array(
'name' => 'StringTrim'
)
),
),
);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment