gpt4 book ai didi

scripting - Zend Form - 从表单类中提取标签值以在 View 脚本中显示的方法?

转载 作者:行者123 更新时间:2023-12-03 08:12:14 25 4
gpt4 key购买 nike

我正在切换表单以使用 View 脚本作为装饰器。到目前为止我看到的示例在 View 脚本中执行以下操作:

<td><label for='textEmail'>Email:</label></td>
<td><?php echo $this->element->textEmail; ?></td>

我想找到一种方法,让表单对象中的文本也显示在标签中。

class RegisterForm extends Zend_Form {
public function init () {
$this->setAction('')
->setMethod('post')
->setAttrib('id','formRegister');

$this->addElement('text', 'textEmail', array('label' => 'Email: '));
$oEmail = $this->getElement('textEmail')
->setRequired(true)
->addFilter('StringTrim')
->addValidator('EmailAddress');
$oEmail->setDecorators(array('ViewHelper', 'Errors'));

$this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/RegisterForm.phtml'))));
}
}

以上是我的表单对象的定义方式。有谁知道如何访问定义的标签值?也许采用以下格式?

<?php echo $this->element->textEmail->label; ?>

这当然行不通。 :p谢谢~

最佳答案

$this->元素->getLabel()

这是我的标准字段 View 脚本:

<div class="field<?php if($this->element->hasErrors()): ?> errors<?php endif; ?>" id="field_<?php echo $this->element->getId(); ?>">
<?php if (0 < strlen($this->element->getLabel())) : ?>
<?php echo $this->formLabel($this->element->getName(), $this->element->getLabel());?>
<?php endif; ?>
<span class="value"><?php echo $this->{$this->element->helper}(
$this->element->getName(),
$this->element->getValue(),
$this->element->getAttribs()
) ?></span>
<?php if ($this->element->hasErrors()) : ?>
<?php echo $this->formErrors($this->element->getMessages()); ?>
<?php endif; ?>
<?php if (0 < strlen($this->element->getDescription())) : ?>
<span class="hint"><?php echo $this->element->getDescription(); ?></span>
<?php endif; ?>
</div>

关于scripting - Zend Form - 从表单类中提取标签值以在 View 脚本中显示的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1398102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com