2014-11-04 76 views
0

我正在通过示例跟随Zend Framework 2.0,现在正在处理Forms章节。似乎一切似乎工作正常,除了我的'密码'和'确认密码'字段似乎不能正确呈现。这里是我定义的密码字段Zend Framework密码字段呈现为'文字'而不是'密码'

class RegisterForm extends Form 
{ 
public function __construct($name = null) 
{ 
    parent::__construct('Register'); 
    $this->setAttribute('method', 'post'); 
    $this->setAttribute('enctype', 'multipart/form-data'); 

     ... 

     $this->add(array(
     'name' => 'password', 
     'attributes' => array(
      'type' => 'password', 
     ), 
     'options' => array(
      'label' => 'Password', 
     ), 
     'attributes' => array(
      'required' => 'required' 
     ), 
     'filters' => array(
      array('name' => 'StringTrim'), 
     ), 
    )); 

但是当它在浏览器中呈现,我得到这个,当我查看网页源我RegisterForm.php文件的摘录...

<dd><input name="password" required="required" type="text" value=""></dd> 

我很确定我已经正确地从书中得到了代码,但是我不确定是否有另一个步骤,我不小心覆盖了RegisterForm.php文件。

回答

2

为什么你重写你的属性?它应该是:

$this->add(array(
     'name' => 'password', 
     'options' => array(
      'label' => 'Password', 
     ), 
     'attributes' => array(
      'type' => 'password', 
      'required' => 'required' 
     ), 
     'filters' => array(
      array('name' => 'StringTrim'), 
     ), 
    )); 
+0

啊哈!这是有道理的。这是完美的。非常感谢你。 – cchapman 2014-11-04 15:00:44

0
'attributes' => array(
    'type' => 'password', 
), 
// ... 
'attributes' => array(
    'required' => 'required' 
), 

认为第二...