Jump to content

[SOLVED] How do I remove form attributes in Zend Framework?


itaym02

Recommended Posts

I have a Form element:

$Form=new Zend_Form;
        $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true))
                 ->setMethod('post')
                 ->setAttrib('id','auth-form')
                 ->removeAttrib('enctype');

 

As can be seen I use the removeAttrib method to remove the default enctype. But, when I echo the form I still get:

 

<form id="auth-form" enctype="application/x-www-form-urlencoded" action="/auth/resetpassword2" method="post">

 

 

Line: 51

    /**#@+
     * Encoding type constants
     */
    const ENCTYPE_URLENCODED = 'application/x-www-form-urlencoded';
    const ENCTYPE_MULTIPART  = 'multipart/form-data';
    /**#@-*/

 

Line: 786

    /**
     * Set encoding type
     * 
     * @param  string $value 
     * @return Zend_Form
     */
    public function setEnctype($value)
    {
        $this->setAttrib('enctype', $value);
        return $this;
    }

    /**
     * Get encoding type
     * 
     * @return string
     */
    public function getEnctype()
    {
        if (null === ($enctype = $this->getAttrib('enctype'))) {
            $enctype = self::ENCTYPE_URLENCODED;
            $this->setAttrib('enctype', $enctype);
        }
        return $this->getAttrib('enctype');
    }

 

As you can see, you may actually be removing the attribute, but as soon as getEnctype() is accessed to write the element the attribute is being overridden.  To remove the 'enctype' attribute just for the sake of removing it doesn't make much sense, it's better to explicitly set it so you and the browser have a better chance of getting data back in an expected format.  I would argue that the default behaviour is preferred in this case .

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.