Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Courses\Form;
- use Zend\InputFilter\InputFilter,
- Zend\Form\Element,
- Zend\Form\Fieldset,
- Zend\Form\Form,
- Zend\InputFilter\Factory as InputFactory,
- Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator,
- Zend\Validator\StringLength,
- Zend\Validator\NotEmpty,
- Zend\Validator\Regex,
- Zend\Form\Factory,
- Zend\Form\Element\Textarea;
- class CourseModeloSaveForm extends Form{
- public function __construct($categorias, $estruturaPai = false)
- {
- parent::__construct();
- $this->setAttribute('method', 'post')
- ->setAttribute('id', 'coursemodelosave')
- ->setAttribute('enctype', 'multipart/form-data')
- ->setHydrator(new ClassMethodsHydrator(false))
- ->setInputFilter(new InputFilter());
- $ccmo_nome = new Element\Text('ccmo_nome');
- $ccmo_nome->setLabel('Nome')
- ->setAttribute('title','Nome do curso')
- ->setAttribute('maxlength',200)
- ->setAttribute('class','span17')
- ->setAttribute('style','width:646px')
- ->setAttribute('id','ccmo_nome')
- ->setAttribute('placeholder','Nome do curso');
- $ccmo_url = new Element\Text('ccmo_url');
- $ccmo_url->setLabel('Endereço da página')
- ->setAttribute('title','Endereço da página')
- ->setAttribute('id','ccmo_url')
- ->setAttribute('size',255)
- ->setAttribute('maxlength',255)
- ->setAttribute('class','span14')
- ->setAttribute('style','margin: 0px 4px;')
- ->setAttribute('id','ccmo_url')
- ->setAttribute('placeholder','Url do curso...Ex: curso-excel-2007-iniciante');
- $ccmo_preco = new Element\Number('ccmo_preco');
- $ccmo_preco->setLabel('Valor do curso')
- ->setLabelAttributes(array('id' => 'lbl_ccmo_preco'))
- ->setAttribute('title','Preço entre R$ 29,90 e R$ 99,99')
- ->setAttribute('size', 7)
- ->setAttribute('maxlength',7)
- ->setAttribute('class','span3')
- ->setAttribute('id','ccmo_preco')
- ->setAttribute('style','display:block')
- ->setAttribute('step','0.01')
- ->setAttribute('description','reais')
- ->setAttribute('placeholder','29,90');
- $categoriasOk = array('' => 'Selecione uma categoria...');
- foreach ($categorias as $categoria) {
- $categoriasOk[$categoria->ccat_id] = $categoria->ccat_nome;
- }
- $categoria = new Element\Select('ccat_id');
- $categoria->setLabel('Categoria')
- ->setAttribute('class','span6')
- ->setAttribute('id', 'categoria')
- ->setAttribute('style', 'margin: -5px 4px')
- ->setValueOptions($categoriasOk);
- if(!$estruturaPai){
- $estruturaOk = array('' => 'Selecione uma sub-categoria...');
- }else{
- $estruturaOk = array();
- foreach ($estruturaPai as $estrutura) {
- if($estrutura['cest_pai'])
- $estruturaOk[$estrutura['cest_id']] = $estrutura['cest_nome'];
- }
- }
- $estruturaPai = $estruturaOk;
- $estrutura = new Element\Select('cest_id');
- $estrutura->setLabel('Sub-Categoria')
- ->setAttribute('class','span7')
- ->setAttribute('id', 'estrutura')
- ->setAttribute('style', 'margin: -5px 4px')
- ->setValueOptions($estruturaPai);
- $ccmo_gratuito = new Element\Select('ccmo_gratuito');
- $ccmo_gratuito->setLabel('Tipo de cobrança')
- ->setAttribute('id', 'ccmo_gratuito')
- ->setEmptyOption('Selecione o tipo de cobrança...')
- ->setValue(0)
- ->setAttribute('onChange', 'cursoGratuito(this.value)')
- ->setValueOptions(array(0 => 'Pago', 1 => 'Gratuito'));
- $ccmo_tag = new Element\Textarea('ccmo_tag');
- $ccmo_tag->setLabel('Palavras-chave')
- ->setAttribute('title','Palavras-chave')
- ->setAttribute('style','margin-top:10px;')
- ->setAttribute('class','span17')
- ->setAttribute('id','ccmo_tag')
- ->setAttribute('placeholder','Ex: curso de excel, preparatório enem, matemática');
- $ccmo_tempo = new Element\Text('ccmo_tempo');
- $ccmo_tempo->setLabel('Tempo')
- ->setAttribute('title','Tempo')
- ->setAttribute('size',100)
- ->setAttribute('maxlength',100)
- ->setAttribute('class','span2')
- ->setAttribute('id','ccmo_tempo')
- ->setAttribute('placeholder','10h');
- $data = array('' => 'Escolha o nível',
- 1 => 'Básico',
- 2 => 'Intermediário',
- 3 => 'Avançado',
- 4 => 'Todos os níveis',);
- $ccmo_nivel = new Element\Select('ccmo_nivel');
- $ccmo_nivel->setLabel('Nivel')
- ->setAttribute('title','Nivel')
- ->setAttribute('class','span4')
- ->setAttribute('id','ccmo_nivel')
- ->setAttribute('placeholder','Básico')
- ->setAttribute('onchange','continuarPreenchimento()')
- ->setValueOptions($data);
- $ccmo_descricao = new Element\Textarea('ccmo_descricao');
- $ccmo_descricao->setLabel('Descrição')
- ->setAttribute('title','Descrição do curso')
- ->setAttribute('id','ccmo_descricao')
- ->setAttribute('rows', 4)
- ->setAttribute('style', 'height:110px')
- ->setAttribute('class','span12')
- ->setAttribute('placeholder','Descrição do curso');
- $file = new Element\File('image-file');
- $file->setLabel('Imagem do curso')
- ->setAttribute('id', 'image-file');
- $submit = new Element\Submit('submit');
- $submit->setAttribute('value','Salvar')
- ->setAttribute('class','btn span3')
- ->setAttribute('id','salvarcurso')
- ->setAttribute('data-loading-text','Salvando...')
- ->setAttribute('style','height:35px');
- $this->add($ccmo_nome)
- ->add($estrutura)
- ->add($categoria)
- ->add($ccmo_gratuito)
- ->add($ccmo_preco)
- ->add($ccmo_tag)
- ->add($ccmo_nivel)
- ->add($ccmo_descricao)
- ->add($file)
- ->add($submit);
- }
- public function getInputFilterForm($id)
- {
- $filter = new InputFilter();
- $factory = new InputFactory();
- $filter->add($factory->createInput(array(
- 'name' => 'ccmo_nome',
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- array('name' => 'StripNewLines'),
- ),
- 'validators' => array(
- array(
- 'name' => 'NotEmpty',
- 'options' => array(
- 'messages' => array(
- NotEmpty::IS_EMPTY => 'Digite o nome do curso',
- ),
- ),
- ),
- ),
- )));
- $filter->add($factory->createInput(array(
- 'name' => 'ccmo_descricao',
- 'allow_empty' => true,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- array('name' => 'StripNewLines'),
- ),
- 'validators' => array(
- array(
- 'name' => 'NotEmpty',
- 'options' => array(
- 'messages' => array(
- NotEmpty::IS_EMPTY => 'Digite a descrição do seu curso',
- ),
- ),
- ),
- array(
- 'name' => 'StringLength',
- 'options' => array(
- 'encoding' => 'UTF-8',
- 'min' => 200,
- 'max' => 999999,
- 'messages' => array(
- StringLength::TOO_LONG => 'Descrição com muitos caracteres',
- StringLength::TOO_SHORT => 'Descrição com poucos caracteres, a descrição deve ter no mínimo 200 caracteres',
- )
- ),
- ),
- ),
- )));
- $filter->add($factory->createInput(array(
- 'name' => 'ccmo_preco',
- 'allow_empty' => true,
- 'filters' => array(
- array('name' => 'Zend\Filter\StringTrim')
- ),
- 'validators' => array(
- array(
- 'name' => 'Between',
- 'options' => array(
- 'encoding' => 'UTF-8',
- 'min' => 14.90,
- 'max' => 999999,
- 'message' => 'Valor mínimo do curso é de R$ 14,90'
- ),
- ),
- ),
- )));
- $filter->add($factory->createInput(array(
- 'name' => 'ccat_id',
- 'allow_empty' => true,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- array('name' => 'StripNewLines'),
- ),
- 'validators' => array(
- array(
- 'name' => 'NotEmpty',
- 'options' => array(
- 'messages' => array(
- NotEmpty::IS_EMPTY => 'Selecione a categoria do seu curso',
- ),
- ),
- ),
- ),
- )));
- $filter->add($factory->createInput(array(
- 'name' => 'cest_id',
- 'allow_empty' => true,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- array('name' => 'StripNewLines'),
- ),
- 'validators' => array(
- array(
- 'name' => 'NotEmpty',
- 'options' => array(
- 'messages' => array(
- NotEmpty::IS_EMPTY => 'Selecione a sub-categoria do seu curso',
- ),
- ),
- ),
- ),
- )));
- $filter->add($factory->createInput(array(
- 'name' => 'ccmo_gratuito',
- 'allow_empty' => true,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- array('name' => 'StripNewLines'),
- ),
- 'validators' => array(
- array(
- 'name' => 'NotEmpty',
- 'options' => array(
- 'messages' => array(
- NotEmpty::IS_EMPTY => 'Selecione o tipo de cobrança do seu curso',
- ),
- ),
- ),
- array(
- 'name' => 'InArray',
- 'options' => array(
- 'haystack' => array(0,1),
- 'messages' => array(
- 'notInArray' => '*'
- ),
- ),
- ),
- ),
- )));
- $filter->add($factory->createInput(array(
- 'name' => 'ccmo_nivel',
- 'allow_empty' => true,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- array('name' => 'StripNewLines'),
- ),
- 'validators' => array(
- array(
- 'name' => 'NotEmpty',
- 'options' => array(
- 'messages' => array(
- NotEmpty::IS_EMPTY => 'Escolha o nível do seu curso',
- ),
- ),
- ),
- ),
- )));
- $filter->add(array('name' => 'image-file',
- 'allow_empty' => true,
- 'validators' => array(
- new \Zend\Validator\File\UploadFile(),
- ),
- ));
- return $filter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment