Zend Form ViewScript 摆脱 dt 和 dd 标签?
我有一个使用 viewscript 使用 zend 构建的表单。我认为通过使用 viewscript,我可以消除所有 dd 和 dt,并且能够在表单脚本文件(patentScriptForm.phtml)的表单上使用我自己的 html 标签?
如何在表单脚本文件中仅使用 div 标签而不使用自动生成的 dt 和 dd 标签?谢谢!!
我有一个非常基本的表单,代码如下:
$age = new Zend_Form_Element_Text('age'); $age->setLabel('age');
$submit = new Zend_Form_Element_Submit('submit'); $submit->setValue($submit);
$this->addElement($age)->addElement($submit);
$this->setDecorators(array ( array ('ViewScript', array('viewScript' => 'patientScriptForm.phtml'))));
下面是我的视图脚本 PatientScriptForm.phtml
<form action="<?php echo $this->escape($this->element->getAction()) ?>" method="<?php echo $this->escape($this->element->getMethod()) ?>">
<div>
<?php echo $this->element->age ?>
</div>
<div>
<?php echo $this->element->submit ?>
</div>
</form>
下面是浏览器输出:
<form action="" method="post">
<div>
<dt id="age-label">
<label for="age" class="optional">age</label>
</dt>
<dd id="age-element">
<input type="text" name="age" id="age" value="" />
</dd>
</div>
<div>
<dt id="submit-label">
</dt>
<dd id="submit-element">
<input type="submit" name="submit" id="submit" value="submit" />
</dd>
</div>
</form>
I have a form build with zend using a viewscript. I thought that by using a viewscript I'd get all the dd and dt eliminated and be able to use my own html tags on the form of the form script file (patientScriptForm.phtml)?
How do I use only the div tags in my form script file and not auto-generated dt and dd tags? Thanks!!
I have a very basic form with code below:
$age = new Zend_Form_Element_Text('age'); $age->setLabel('age');
$submit = new Zend_Form_Element_Submit('submit'); $submit->setValue($submit);
$this->addElement($age)->addElement($submit);
$this->setDecorators(array ( array ('ViewScript', array('viewScript' => 'patientScriptForm.phtml'))));
Below is my viewscript patientScriptForm.phtml
<form action="<?php echo $this->escape($this->element->getAction()) ?>" method="<?php echo $this->escape($this->element->getMethod()) ?>">
<div>
<?php echo $this->element->age ?>
</div>
<div>
<?php echo $this->element->submit ?>
</div>
</form>
Below is the browser output:
<form action="" method="post">
<div>
<dt id="age-label">
<label for="age" class="optional">age</label>
</dt>
<dd id="age-element">
<input type="text" name="age" id="age" value="" />
</dd>
</div>
<div>
<dt id="submit-label">
</dt>
<dd id="submit-element">
<input type="submit" name="submit" id="submit" value="submit" />
</dd>
</div>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是,虽然使用表单的
ViewScript
装饰器适用于表单元素本身,但每个元素都有自己的默认装饰器方案。视图脚本中的一个简单解决方案可能是
The problem is that whilst using the
ViewScript
decorator for the form works for the form element itself, your elements each have their own default decorator scheme.A simple solution in your view script could be
如果您的表单包含太多元素,以至于附加
到视图脚本中每个 echo 语句的末尾似乎不太引人注目,您还可以执行以下操作,这与对视图脚本中的每个元素执行上述调用具有相同的效果形式:
If your form has too many elements that appending
to the end of each echo statement in your view script doesn't seem so compelling, you can also do the following, which has the same effect as doing the above call for every single element in your form: