如何使用Zend Form设置密码的值

时间:2015-12-05 05:47:26

标签: zend-framework zend-form

Zend Frame中的这个My Edit用户表单

  $this->setAttrib('enctype', 'multipart/form-data');
    $this->setName('user');
    $id = new Zend_Form_Element_Hidden('id');
    $id->addFilter('Int');
    $fname = new Zend_Form_Element_Text('fname');
    $fname->setLabel('Full Name')
            ->setRequired(true)
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');
    $email = new Zend_Form_Element_Text('email');
    $email->setLabel('Email Address')
            ->setRequired(true)
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');
    $add = new Zend_Form_Element_Text('add');
    $add->setLabel('Address')
            ->setRequired(true)
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');
    $pass = new Zend_Form_Element_Password('pass');
    $pass->setLabel('Password')
            ->setRequired(true)
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');

    $city = new Zend_Form_Element_Text('city');
    $city->setLabel('city')
            ->setRequired(true)
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');
    $img = new Zend_Form_Element_File('img');
    $img->setLabel('Profile picture')
            ->setRequired(true);


    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setAttrib('id', 'submitbutton');

    // add element in form
    $this->addElements(array($id, $fname, $email, $add, $pass, $city, $img, $submit));

我使用控制器

中的以下代码设置表单元素的值
  $form = new Application_Form_User();
    $form->submit->setLabel('Save');
    $this->view->form = $form;

   $id = $this->_getParam('id', 0);
        if ($id > 0) {
            $user = new Application_Model_DbTable_User();
            $info = $user->getUser($id);
            //$form->populate($info);
            $form->setDefaults($info);

我使用$ form-> setDefaults($ info);用于为表单字段设置vlaue的方法。此方法仅为Text输入类型设置值,但此方法无法设置输入类型为password的值。那么,对于输入类型的set vlaue,我该怎么做才是密码? 这是我的输出屏幕edit.php

 edit.php

1 个答案:

答案 0 :(得分:0)

Zend不允许自动填写密码字段。 Html type =“password”也会阻止浏览器支持自动完成。每次刷新页面时,您都必须手动输入密码。

但是要在字段上禁用自动完成功能。

$foo = new Zend_Form_Element_Text('foo', array( 
        'autocomplete' => 'off', 
    )); 

    // or... 
    $form->addElement('text', 'foo', array( 
        'autocomplete' => 'off', 
    )); 

    // or... 
    $element->autocomplete = 'off';