Note that there are some explanatory texts on larger screens.

plurals
  1. POZend Form + Twitter bootstrap: creating 2 spans to show the same form
    primarykey
    data
    text
    <p>I'm almost getting insane trying to complete this automated form in Zend_Form, I already did almost everything, and all thanks to Stackoverflow community. here's what I want to do, I'll try to make myself clear (I'm hard to explain myself -_-''):</p> <p>what I have already done: Wrap each element label and input inside a div, and each one with a proper twitter span class to populate a superior div, and the form itself receives an array of data and generates it automatically.</p> <p>What I need: My Superior Div is Span:12 (in Layout) I need the content to have 2 "Span:6" divs, and each div to hold parts of the same form.</p> <p>Solutions I cam up with:</p> <p>One of my Solutions is to get each element individually and place manually in each span6 div. The other is to create a 'container' parameter in my function, so the generator can do that (but I dont know how to create 2 div with span classes and append the elements in the respective one)</p> <p>I hope u guys understood what I'm trying to do and what I need, thanks =)</p> <pre><code>form/Usuario: &lt;?php class Admin_Form_Usuario extends Zene_Form_Helper_Abstract { protected $campo = null; /** * Initialize form (used by extending classes) * * @return void */ public function init() { //Valores dos Campos $model = new Admin_Model_Usuario(); $option = $model-&gt;getOptions(); $modelPage = new Admin_Model_Page(); $optionPage = $modelPage-&gt;getOptions(); //Atributos dos Campos $this-&gt;campo = array( array('Tipo'=&gt;'Text', 'Id'=&gt;'UsuId', 'Label'=&gt;'Código do Usuário', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'UsuId','Atributo'=&gt;array('readonly'=&gt;'true')), array('Tipo'=&gt;'Select', 'Id'=&gt;'UsuFunId', 'Label'=&gt;'Funcionário', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'UsuFunId','Option'=&gt;array(1=&gt;'Guest',2=&gt;'Charles')), array('Tipo'=&gt;'Text', 'Id'=&gt;'UsuLogin', 'Label'=&gt;'Login do Usuário', 'Span' =&gt;'12', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'UsuId'), array('Tipo'=&gt;'Pass', 'Id'=&gt;'UsuSenha', 'Label'=&gt;'Senha Usuário', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'UsuSenha'), array('Tipo'=&gt;'Pass', 'Id'=&gt;'ConfUsuSenha', 'Label'=&gt;'Confirmar Senha', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'ConfUsuSenha'), array('Tipo'=&gt;'Check', 'Id'=&gt;'full_permission','Label'=&gt;'Permissão Total', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'full_permission'), array('Tipo'=&gt;'Check', 'Id'=&gt;'UsuAtivo', 'Label'=&gt;'Ativo', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'UsuAtivo'), array('Tipo'=&gt;'Date', 'Id'=&gt;'UsuDtAtivo', 'Label'=&gt;'Data ativação', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'UsuDtAtivo','Atributo'=&gt;array('readonly'=&gt;'true')), array('Tipo'=&gt;'Date', 'Id'=&gt;'UsuDtDesativo', 'Label'=&gt;'Data Desativação', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'UsuDtDesativo','Atributo'=&gt;array('readonly'=&gt;'true')), array('Tipo'=&gt;'Select', 'Id'=&gt;'Parent_id', 'Label'=&gt;'Grupo', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'Parent_id','Option'=&gt;$option), //array('Tipo'=&gt;'MSelect','Id'=&gt;'Parent_id', 'Label'=&gt;'Grupo', 'Span' =&gt;'6', 'Required'=&gt;'true', 'Table'=&gt;'Usuario','Field'=&gt;'Parent_id','Option'=&gt;$option), array('Tipo'=&gt;'Submit', 'Id'=&gt;'save', 'Label'=&gt;'Salvar', 'Span' =&gt;'12' ) ); parent::createElemento($this-&gt;campo); } Helper Abstract (gera o form) e o executa o `parent::createElemento()` &lt;?php abstract class Zene_Form_Helper_Abstract extends Zend_Form{ /** * Metodo para retornar um lemento criado apartir de um array * deve seguir a seguinte estrutura; * @see Zend_Form::getElement() */ public function createElemento(array $options){ $element = null; foreach ($options as $option) { switch ($option['Tipo']) { case 'Hidden': $element = new Zend_Form_Element_Hidden($option['Id']); break; case 'Select': $element = new Zend_Form_Element_Select($option['Id']); $element-&gt;addMultiOptions($option['Option']); break; case 'Date': $element = new Zend_Form_Element_Text($option['Id']); $element-&gt;setAttrib("class", "datepicker"); break; case 'Check': $element = new Zend_Form_Element_Checkbox($option['Id']); break; case 'MCheck': $element = new Zend_Form_Element_MultiCheckbox($option['Id']); $element-&gt;addMultiOptions($option['Option']); break; case 'Text': $element = new Zend_Form_Element_Text($option['Id']); break; case 'Pass': $element = new Zend_Form_Element_Password($option['Id']); break; case 'Checkbox': $element = new Zend_Form_Element_Checkbox($option['Id']); break; case 'Textarea': $element = new Zend_Form_Element_Textarea($option['Id']); break; case 'MSelect': $element = new Zend_Form_Element_Multiselect($option['Id']); $element-&gt;addMultiOptions($option['Option']); break; case 'Submit': $elementDecorator = array( array('ViewHelper'), array('HtmlTag', array('tag' =&gt; 'div','style' =&gt;'margin-left:0', 'class' =&gt; 'span'.$option['Span'])), ); $element = new Zend_Form_Element_Button($option['Id']); $element-&gt;setLabel($option['Label']) -&gt;setAttrib('type','submit') -&gt;setAttrib('class','btn btn-primary') -&gt;setDecorators($elementDecorator); break; default: break; } $elementDecorator = array( array('ViewHelper'), array('Label'), array('HtmlTag', array('tag' =&gt; 'div','style' =&gt;'margin-left:0', 'class' =&gt; 'span'.$option['Span'])), ); if(isset($option['Atributo'])){ foreach ($option['Atributo'] as $key=&gt;$value) { $element-&gt;setAttrib($key, $value); } } if(($option['Tipo'] != 'Submit') &amp;&amp; ($option['Tipo'] != 'Button')){ $element-&gt;setLabel($option['Label']) -&gt;setAllowEmpty((bool)$option['Required']) -&gt;setRequired(!$option['Required']) -&gt;addValidator('Db_NoRecordExists', false, array( 'table' =&gt; $option['Table'], 'field' =&gt; $option['Field'] ) )-&gt;setDecorators($elementDecorator); if ($option['Disabled'] == 'true') $element-&gt;setAttrib('disabled','disabled'); } $this-&gt;addElement($element); } } no usuario/controller: $form = new Admin_Form_Usuario(); no usuario/view: $this-&gt;view-&gt;form = $form; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload