【发布时间】:2011-05-14 16:01:48
【问题描述】:
使用 Zend 框架创建此表单时,我希望输出使用 doctype strict 进行验证,但它失败了,因为输入没有结束标记“/>”。
我怎样才能让它通过验证?
形式:
require_once "Zend/Form.php";
require_once "Zend/Form/Element/Text.php";
require_once "Zend/Form/Element/Submit.php";
class Form_Test extends Zend_Form
{
public function init()
{
// Email
$email = new Zend_Form_Element_Text('email');
$email->setRequired(true)
->addValidator('EmailAddress')
->setLabel("Email Address");
// Submit
$submit = new Zend_Form_Element_Submit('login');
$submit->setLabel('Login');
// Add element to form.
$this->addElements(array(
$email,
$submit
));
$this->setLegend('Login');
$this->setElementDecorators(array(
'ViewHelper',
array('Label', array('separator' => '', 'requiredPrefix' => '* ')),
array('HtmlTag', array('tag' => 'p', 'class' => 'form-element')),
));
// Buttons do not need labels
$submit->setDecorators(array(
array('ViewHelper'),
array('HtmlTag', array('tag' => 'p', 'class' => 'submit-button'))
));
$this->getDecorator('HtmlTag')->setOption('tag', 'div');
$this->getDecorator('HtmlTag')->setOption('class', 'form');
}
}
html 输出:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-CA" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form test</title>
</head>
<body>
<form enctype="application/x-www-form-urlencoded" action="" method="post">
<div>
<p class="form-element">
<label for="email" class="required">* Email Address</label>
<input type="text" name="email" id="email" value="">
</p>
<p class="submit-button">
<input type="submit" name="login" id="login" value="Login">
</p>
</div>
</form>
</body>
</html>
【问题讨论】:
-
您可能想检查表单装饰器,您将能够编写自己的标记。
标签: zend-framework zend-form html-parsing decorator