I tried to build a table grid. I wanted to see all relationed records and at the end a free row to add a new record. (All controllers, modules ... work fine if I build a single Form)
This is a code snippet index.phtml:
foreach($this->aktermine as $termin) :
?>
<tr>
<td class="row_<?PHP echo $i % 2;?>"><?php echo $this->escape($termin->nr);?></td>
<td class="row_<?PHP echo $i % 2;?>"><?php echo $this->escape($termin->kopfnr);?></td>
<td class="row_<?PHP echo $i % 2;?>"><?php echo $this->escape($termin->datum);?></td>
<td class="row_<?PHP echo $i % 2;?>"><?php echo $this->escape($termin->zeit);?></td>
<td class="row_<?PHP echo $i % 2;?>"><?php echo $this->escape($termin->thema);?></td>
<td></td>
</tr>
<?php
$i=$i+1;
endforeach;
?>
<tr>
<td class="row_<?PHP echo $i % 2;?>"><input name="nr1" type="text" size="2" maxlength="2"></td>
<td class="row_<?PHP echo $i % 2;?>"><input name="kopfnr1" type="text" size="2" maxlength="2"></td>
<td class="row_<?PHP echo $i % 2;?>"><input name="datum1" type="text" size="10" maxlength="10" ></td>
<td class="row_<?PHP echo $i % 2;?>"><input name="zeit1" type="text" size="10" maxlength="10"></td>
<td class="row_<?PHP echo $i % 2;?>"><input name="thema1" type="text" size="30" maxlength="30"></td>
</tr>
<a href="<?php echo $this->url(array('controller'=>'aktermine','action'=>'add', 'kopfnr'=>$termin->kopfnr));?>">Speichern</a>
In my controller add action I want to use the values from the last row (named with *1). I of course get the kopf nr with:
$knr = $this->_getParam('kopfnr', 0);
But how can I send and get the other values?
Here ist my form class I used before:
class Application_Form_Aktermine extends Zend_Form
{
public function init()
{
$this->setName('Arbeitskalender Termine');
$nr = new Zend_Form_Element_Text('nr');
$nr->addFilter('Int');
$kopfnr = new Zend_Form_Element_Text('kopfnr');
$kopfnr->addFilter('Int');
$datum = new Zend_Form_Element_Text('datum');
$datum->setLabel('datum')
->addValidator(New Zend_Validate_Date('MM-DD-YYYY'))
->setAttrib('size', '20');
$zeit = new Zend_Form_Element_Text('zeit');
$zeit->setLabel('zeit')
->addValidator(new Zend_Validate_Date(array('format' => 'H:i:s')))
->setAttrib('size', '20');
$thema = new Zend_Form_Element_Text('thema');
$thema->setLabel('thema')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('loge', 'submitbutton');
$this->addElements(array($nr, $kopfnr,$datum, $zeit, $thema, $submit));
}
}
How can I change it to table view?
Please do not use HTML inputs. You should use your Application_Form_Aktermine
in your view. If you want to render your form in a table you could use From Decorators
You could for example have a table with two columns, the first one for label
and the second one for the Zend_Form_Element
.
In init()
function of your Application_Form_Aktermine
classe, do something like :
public function init()
{
// decorators here for form elements
$elementDecoration = array(
'ViewHelper',
'Description',
'Errors',
array(array('data'=>'HtmlTag'), array('tag' => 'td', 'valign' => 'TOP')),
array('Label', array('tag' => 'td')),
array('Errors'),
array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
);
// decorators here for button
$buttonDecoration = array(
'ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
//form decoration
$formDecoration = array(
'FormElements',
array(array('data'=>'HtmlTag'), array('tag'=>'table', 'class'=>'forms')),
'Form'
);
// the rest of your code
// just add ->setDecorators() for every element
$this->setName('Arbeitskalender Termine');
$nr = new Zend_Form_Element_Text('nr');
$nr->addFilter('Int')
->setDecorators($elementDecoration);
$kopfnr = new Zend_Form_Element_Text('kopfnr');
$kopfnr->addFilter('Int')
->setDecorators($elementDecoration);
$datum = new Zend_Form_Element_Text('datum');
$datum->setLabel('datum')
->addValidator(New Zend_Validate_Date('MM-DD-YYYY'))
->setAttrib('size', '20')
->setDecorators($elementDecoration);
$zeit = new Zend_Form_Element_Text('zeit');
$zeit->setLabel('zeit')
->addValidator(new Zend_Validate_Date(array('format' => 'H:i:s')))
->setAttrib('size', '20')
->setDecorators($elementDecoration);
$thema = new Zend_Form_Element_Text('thema');
$thema->setLabel('thema')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty')
->setDecorators($elementDecoration);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('loge', 'submitbutton')
->setDecorators($buttonDecoration);
// add for decorator to your form
$this->setDecorators($formDecoration);
$this->addElements(array($nr, $kopfnr,$datum, $zeit, $thema, $submit));
}
Here is a post with more details on how to use Zend_Form_Decorators
to create tableview for your form.