从我的 HTML 字段获取值
getting values from my HTML Fields
我试图构建一个 table 网格。我想查看所有相关记录,并在末尾有一个空行来添加新记录。
(所有控制器、模块……如果我构建一个表单,就可以正常工作)
这是一个代码片段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>
在我的控制器添加操作中,我想使用最后一行的值(以 *1 命名)。我当然得到了 kopf nr:
$knr = $this->_getParam('kopfnr', 0);
但是如何发送和获取其他值?
这是我的表格 class 我以前用过:
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));
}
}
如何将其更改为 table 视图?
请不要使用 HTML 输入 。您应该在您的视图中使用 Application_Form_Aktermine
。如果你想在 table 中呈现你的表单,你可以使用 From Decorators
例如,您可以有一个包含两列的 table,第一列用于 label
,第二列用于 Zend_Form_Element
。
在 Application_Form_Aktermine
类的 init()
函数中,执行如下操作:
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));
}
这里是 post,其中包含有关如何使用 Zend_Form_Decorators
为您的表单创建 table 视图的更多详细信息。
我试图构建一个 table 网格。我想查看所有相关记录,并在末尾有一个空行来添加新记录。 (所有控制器、模块……如果我构建一个表单,就可以正常工作)
这是一个代码片段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>
在我的控制器添加操作中,我想使用最后一行的值(以 *1 命名)。我当然得到了 kopf nr:
$knr = $this->_getParam('kopfnr', 0);
但是如何发送和获取其他值?
这是我的表格 class 我以前用过:
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));
}
}
如何将其更改为 table 视图?
请不要使用 HTML 输入 。您应该在您的视图中使用 Application_Form_Aktermine
。如果你想在 table 中呈现你的表单,你可以使用 From Decorators
例如,您可以有一个包含两列的 table,第一列用于 label
,第二列用于 Zend_Form_Element
。
在 Application_Form_Aktermine
类的 init()
函数中,执行如下操作:
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));
}
这里是 post,其中包含有关如何使用 Zend_Form_Decorators
为您的表单创建 table 视图的更多详细信息。