从我的HTML字段中获取值

时间:2015-04-11 16:41:03

标签: zend-framework zend-form

我试图构建一个表格。我希望查看所有关联记录,最后添加一个自由行来添加新记录。 (如果我构建一个表单,所有控制器,模块......都可以正常工作)

这是一段代码片段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 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));

    }
}

如何将其更改为表格视图?

1 个答案:

答案 0 :(得分:1)

请不要使用HTML输入。您应该在视图中使用Application_Form_Aktermine。如果您想在表格中呈现表单,可以使用From Decorators

例如,您可以拥有一个包含两列的表格,第一列为label,第二列为Zend_Form_Element

init() classe的Application_Form_Aktermine函数中,执行以下操作:

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为您的表单创建tableview。

希望这可以提供帮助。