Jump to content

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


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 .

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.