views:

46

answers:

4

Zend adds an enctype to all forms. What's that good for? and how can I remove it?

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

</form>
+4  A: 

It is not possible without patching Zend_Form class or deriving from it and overriding getEnctype()

http://framework.zend.com/svn/framework/standard/tags/release-1.10.8/library/Zend/Form.php

Look at the getEnctype() method.

zerkms
+6  A: 

enctype="application/x-www-form-urlencoded" is a formality requirement of the POST method. http://www.w3.org/TR/html401/interact/forms.html

stillstanding
Where is it specified that `enctype` is a required parameter?
zerkms
This is the default value for POST forms. You need not specify it but the browser will still send it to the server.
stillstanding
As mentioned, it's the default. In the case of file uploads, you do have to specify multipart/form-data as enctype.
stillstanding
+1  A: 

If you want to remove it, you have to override the getOptions method of Zend_Form_Decorator_Form and remove the two lines below :

class Zend_Form_Decorator_Form extends Zend_Form_Decorator_Abstract
{

    [..]

    public function getOptions()
    {
        if (null !== ($element = $this->getElement())) {
            if ($element instanceof Zend_Form) {
                [..]
                // To remove
                if ($method == Zend_Form::METHOD_POST) {
                    $this->setOption('enctype', 'application/x-www-form-urlencoded');
                }
                [..]
Maxence
A: 

It is an atribute used to identify what kind of form are you trying to post to the server. In this case it is saying that you send text information. In case you would like to send files e.g. sth more complex you should use "multipart/form-data" value of enctype. See http://www.w3.org/TR/html401/interact/forms.html#adef-enctype for more information.

Bery