public function init() { // init the parent parent::init(); // set the form's method $this->setMethod('post'); $id = new Zend_Form_Element_Hidden('id'); $id->setOptions(array('validators' => array(new Zend_Validate_Regex('/^\\d*$/')))); $this->addElement($id); $firstname = new Zend_Form_Element_Text('firstname'); $firstname->setOptions(array('label' => $this->t('First name'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty'))); $this->addElement($firstname); $lastname = new Zend_Form_Element_Text('lastname'); $lastname->setOptions(array('label' => $this->t('Last name'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty'))); $this->addElement($lastname); $checkEmailNotJunk = new Zend_Validate_Callback(array($this, 'emailNotJetable')); $uniqueEmailValidator = new Zend_Validate_Db_NoRecordExists(array('table' => 'backoffice_users', 'field' => 'email')); $email = new Zend_Form_Element_Text('email'); $email->setOptions(array('label' => $this->t('Email'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty', $checkEmailNotJunk, $uniqueEmailValidator))); $this->addElement($email); $raisonsocial = new Zend_Form_Element_Text('raison sociale'); $raisonsocial->setOptions(array('label' => $this->t('Raison sociale'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty'))); $this->addElement($raisonsocial); // $groupsInArrayValidator = new Zend_Validate_InArray(array_keys(array(1, 2, 3))); // $groupsInArrayValidator->setMessage('Please select at least one group. If you are not sure about which group is better, select "member".'); $status = new Zend_Form_Element_Radio('status'); $status->setOptions(array('label' => $this->t('Status'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty'), 'multiOptions' => array('Gérant' => 'Gérant', 'Associé' => 'Associé', 'Freelance patenté' => 'Freelance patenté'))); $this->addElement($status); $submit = new Zend_Form_Element_Submit('submit'); $submit->setOptions(array('label' => $this->t('Save user'), 'required' => true, 'order' => 100)); $this->addElement($submit); }
/** * Overrides init() in Zend_Form * * @access public * @return void */ public function init() { // init the parent parent::init(); // set the form's method // set the form's method $this->setAction('/contact/listmycontact')->setMethod('post'); $firstName = new Zend_Form_Element_Text('search'); $firstName->setOptions(array('value' => $this->t('Search'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty'))); $this->addElement($firstName); $status = new Zend_Form_Element_Radio('status'); $status->setOptions(array('label' => $this->t('Type'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty'), 'multiOptions' => array('Reseau' => 'Réseau', 'Mycontact' => 'Mes Contacts'))); $this->addElement($status); $submit = new Zend_Form_Element_Submit('submit_search'); $submit->setOptions(array('label' => $this->t('Search'), 'required' => true)); $this->addElement($submit); }
/** * Overrides init() in Zend_Form * * @access public * @return void */ public function init() { // init the parent parent::init(); // set the form's method $this->setMethod('post'); $raisonsocial = new Zend_Form_Element_Text('raison sociale'); $raisonsocial->setOptions(array('label' => $this->t('Raison sociale'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty'))); $this->addElement($raisonsocial); // $groupsInArrayValidator = new Zend_Validate_InArray(array_keys(array(1, 2, 3))); // $groupsInArrayValidator->setMessage('Please select at least one group. If you are not sure about which group is better, select "member".'); $status = new Zend_Form_Element_Radio('status'); $status->setOptions(array('label' => $this->t('Status'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty'), 'multiOptions' => array('Gérant' => 'Gérant', 'Associé' => 'Associé', 'Freelance patenté' => 'Freelance patenté'))); $this->addElement($status); $submit = new Zend_Form_Element_Submit('submit'); $submit->setOptions(array('label' => $this->t('Save user'), 'required' => true, 'order' => 100)); $this->addElement($submit); }
public function init() { $this->setMethod("post"); // produto_nome $produto_nome = new Zend_Form_Element_Text("produto_nome"); $produto_nome->setLabel("Nome"); $produto_nome->setRequired(); $produto_nome->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe o nome do produto')); $produto_nome->setDecorators(App_Forms_Decorators::$simpleElementDecorators); // produto_id $produto_id = new Zend_Form_Element_Hidden("produto_id"); // fabricante_nome $fabricante_nome = new Zend_Form_Element_Text("fabricante_nome"); $fabricante_nome->setLabel("Fabricante"); //$fabricante_nome->setRequired(); $fabricante_nome->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe o nome do fabricante')); $fabricante_nome->setDecorators(App_Forms_Decorators::$simpleElementDecorators); // fabricante_id $fabricante_id = new Zend_Form_Element_Hidden("fabricante_id"); // marca_nome $marca_nome = new Zend_Form_Element_Text("marca_nome"); $marca_nome->setLabel("Marca"); $marca_nome->setRequired(); $marca_nome->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe o nome da marca')); $marca_nome->setDecorators(App_Forms_Decorators::$simpleElementDecorators); // marca_id $marca_id = new Zend_Form_Element_Hidden("marca_id"); // reclamacao_nome $reclamacao_nome = new Zend_Form_Element_Text("reclamacao_nome"); $reclamacao_nome->setLabel("Nome"); $reclamacao_nome->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe seu nome')); // reclamacap_email $reclamacao_email = new Zend_Form_Element_Text("reclamacao_email"); $reclamacao_email->setLabel("E-mail"); $reclamacao_email->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe seu e-mail')); // reclamacao_empresa $reclamacao_empresa = new Zend_Form_Element_Text("reclamacao_empresa"); $reclamacao_empresa->setLabel("Empresa onde comprou o produto"); $reclamacao_empresa->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe seu e-mail')); // reclamacao_cidade $reclamacao_cidade = new Zend_Form_Element_Text("reclamacao_cidade"); $reclamacao_cidade->setLabel("Cidade"); $reclamacao_cidade->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe sua cidade')); // reclamacao_estado $reclamacao_estado = new Zend_Form_Element_Select("reclamacao_estado"); $reclamacao_estado->setLabel("Estado"); $reclamacao_estado->setAttribs(array('class' => 'form-control')); $reclamacao_estado->setMultiOptions($this->getEstados()); // reclamacao_descricao $reclamacao_descricao = new Zend_Form_Element_Textarea("reclamacao_descricao"); $reclamacao_descricao->setLabel("Descreva sua reclamação"); $reclamacao_descricao->setRequired(); $reclamacao_descricao->setDecorators(App_Forms_Decorators::$simpleElementDecorators); $reclamacao_descricao->setAttribs(array('class' => 'form-control', 'rows' => 5, 'placeholder' => 'Informe porque você está insatisfeito com o produto', 'maxlenght' => 500)); $reclamacao_descricao->addValidator(new App_Validate_Reclamacao()); // reclamacao_nota $reclamacao_nota = new Zend_Form_Element_Radio("reclamacao_nota"); $reclamacao_nota->setLabel("Dê sua nota para o produto"); $reclamacao_nota->setRequired(); $reclamacao_nota->setAttribs(array('class' => '')); $reclamacao_nota->setMultiOptions($this->getNotasHtml()); $reclamacao_nota->setOptions(array('escape' => false)); $reclamacao_nota->setSeparator(" "); $reclamacao_nota->setDecorators(App_Forms_Decorators::$checkboxElementDecorators); // submit $submit = new Zend_Form_Element_Submit("submit"); $submit->setLabel("Registrar Reclamação"); $submit->setAttrib("class", 'form-control btn btn-success'); $this->addElements(array($produto_nome, $fabricante_nome, $marca_nome, $reclamacao_descricao, $reclamacao_nome, $reclamacao_email, $reclamacao_cidade, $reclamacao_estado, $reclamacao_nota, $submit, $produto_id, $marca_id, $fabricante_id)); }
/** * Функция создание формы * @param type $objForm объект формы * @param type $elementsForm элементы в виде массива * @return type объект формы */ protected function createFormElements($objForm, $elementsForm) { foreach ($elementsForm as $key => $value) { // определяем тип по умолчанию $type = !empty($value['type']) ? $value['type'] : 'text'; // массив с опциями $params = array(); if ($type !== 'hidden') { $params['label'] = !empty($value['label']) ? $value['label'] : die('Не оределлен атрибут label!'); } $params['decorators'] = !empty($value['decorators']) ? $value['decorators'] : $this->elementDecorators(); if (!empty($value['multiOptions'])) { $params['multiOptions'] = $value['multiOptions']; } $value['required'] = !empty($value['required']) ? $value['required'] : true; $value['attribs'] = !empty($value['attribs']) ? $value['attribs'] : array('class' => 'form-control'); $value['filters'] = !empty($value['filters']) ? $value['filters'] : ''; $value['validators'] = !empty($value['validators']) ? $value['validators'] : ''; // присваевыем стандартные фильтры и валидаторы if (empty($value['filters'])) { $stringTrim = new Zend_Filter_StringTrim(); $stripTags = new Zend_Filter_StripTags(); $value['filters'] = array('stringTrim' => $stringTrim, 'stripTags' => $stripTags); } if (empty($value['validators'])) { $alnum = new Zend_Validate_Alnum(); $alnum->setMessage('Только буквы и цыфры!'); $notEmpty = new Zend_Validate_NotEmpty(); $notEmpty->setMessage('Поле обязательно для заполнения', 'isEmpty'); $value['validators'] = array('alnum' => $alnum, 'notEmpty' => $notEmpty); } // провеки на тип если нужен новый то надо добавить по аналогии switch ($type) { case 'text': $elem = new Zend_Form_Element_Text($key); break; case 'textarea': $elem = new Zend_Form_Element_Textarea($key); break; case 'select': $elem = new Zend_Form_Element_Select($key); break; case 'password': $elem = new Zend_Form_Element_Password($key); break; case 'hidden': $elem = new Zend_Form_Element_Hidden($key); break; case 'radio': $elem = new Zend_Form_Element_Radio($key); break; } // присваиваем атрибуты if (!empty($value['attribs'])) { foreach ($value['attribs'] as $k => $val) { $params[$k] = $val; } } // присваиваем опции if (!empty($elem)) { $elem->setOptions($params); } // добавляем валидаторы if (!empty($value['validators']) && $type !== 'hidden') { foreach ($value['validators'] as $val) { $elem->addValidator($val); } } // добавляем фильтры if (!empty($value['filters']) && $type !== 'hidden') { foreach ($value['filters'] as $val) { $elem->addFilter($val); } } // вот тут писец if (!empty($value['required']) && $type !== 'hidden') { $elem->setRequired(TRUE); } // добавляем элемент на форму $objForm->addElement($elem); } // добавляем кнопку $objForm->addElement('submit', 'submit', array('label' => $this->buttonLabel, 'decorators' => $this->buttonDecorators(), 'class' => 'btn btn-default')); return $objForm; }