public function init() { $this->setMethod('post')->setAttrib('id', 'frmProducto'); // Elemento: Nombre $e = new Zend_Form_Element_Text('nombre'); $e->setLabel('Nombre'); $e->setAttrib('maxlength', '50'); $e->setRequired(true); $v = new Zend_Validate_StringLength(array('min' => 5, 'max' => 50)); $v->setMessage("El nombre del producto debe tener debe tener al menos\n %min% characters. '%value%' no cumple ese requisito", Zend_Validate_StringLength::TOO_SHORT); $e->addValidator($v); $this->addElement($e); // Elemento: Precio $e = new Zend_Form_Element_Text('precio'); $e->setLabel('Precio'); $e->setRequired(true); $v = new Zend_Validate_Between(array('min' => 0.1, 'max' => 9999)); $e->addValidator($v); $v = new Zend_Validate_Float(new Zend_Locale('US')); $e->addValidator($v); $e->setAttrib('maxlength', '7'); $this->addElement($e); //Elemento: Categoria $e = new Zend_Form_Element_Select('id_categoria'); $e->setLabel('Categoria'); $_cat = new Application_Model_Categoria(); $values = $_cat->getComboValues(); $e->addMultiOption(-1, '--- Categoría ---'); $e->addMultiOptions($values); $this->addElement($e); $v = new Zend_Validate_InArray(array_keys($values)); $e->addValidator($v); //Elemento: Fabricante $e = new Zend_Form_Element_Select('id_fabricante'); $e->setLabel('Fabricante'); $_fab = new Application_Model_Fabricante(); $values = $_fab->getComboValues(); $e->addMultiOption(-1, '--- Fabricante ---'); $e->addMultiOptions($values); $this->addElement($e); $v = new Zend_Validate_InArray(array_keys($values)); $e->addValidator($v); $this->addElement('submit', 'Enviar'); }
public function init() { $this->setMethod('post')->setAttrib('id', 'frmTest')->setAttrib('enctype', 'multipart/form-data'); // Elemento: Nombre $e = new Zend_Form_Element_Text('nombre'); $e->setLabel('Nombre'); $e->setFilters(array('StringToLower')); $this->addElement($e); // Elemento: activo $e = new Zend_Form_Element_Checkbox('activo'); $e->setLabel('Activo'); $this->addElement($e); // Elemento: activo2 $e = new Zend_Form_Element_Radio('activo2'); $e->setLabel('Activo2'); $_cat = new Application_Model_Categoria(); $values = $_cat->getComboValues(); $e->setMultiOptions($values); $e->setValue(array_rand($values)); $v = new Zend_Validate_InArray(array_keys($values)); $this->addElement($e); $e = new Zend_Form_Element_File('imagen'); $e->setLabel('Upload an image:'); $e->setDestination(APPLICATION_PATH . '/../public/uploads/'); $f = new Zend_Filter_File_Rename(array('target' => '123.jpg')); // Renombrar archivo $e->addFilter($f); $e->addValidator('Count', false, 1); // Solo 1 archivo $e->addValidator('Size', false, 102400); // limite de 100K $e->addValidator('Extension', false, 'jpg,png,gif'); // solo JPEG, PNG, and GIFs $this->addElement($e); $this->addElement('submit', 'Enviar'); }