Issues

ZF-4586: Zend_Form_Element_File does not work without filters

Issue Type: Bug Created: 2008-10-13T09:07:17.000+0000 Last Updated: 2008-11-13T14:10:26.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: Martin Hujer (mhujer) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

Related issues: Attachments:

Description

Zend_Form_Element_File does not work without filters.

It dies on 'Fatal error: Unsupported operand types in Zend\File\Transfer\Adapter\Abstract.php on line 796', when no filter is set. It is some kind of array merging problem.

When I add a filter, ->addFilter(new Zend_Filter_File_Rename('XXX', 'XXX')), it works OK

Comments

Posted by Thomas Weidner (thomas) on 2008-10-13T11:01:07.000+0000

Is works without filters. Most of the unittests are done without attached filters.

Please give reproducable code so we can investigate the problem in the file element.

Posted by Martin Hujer (mhujer) on 2008-10-13T11:09:48.000+0000

Problem is with $form->getValues()

<pre class="highlight">
        $form = new Zend_Form();
        $form->setName('upload_form');
        
        $form->setMethod(Zend_Form::METHOD_POST);
        $form->setEnctype('multipart/form-data');
        
        $element = new Zend_Form_Element_File('upload_file');
        $element->setLabel('Upload:')
            ->setDestination('C:\Temp')
            //->addFilter(new Zend_Filter_File_Rename('XXX', 'XXX')) //uncomment to get example working
            ;
        $form->addElement($element);
        
        $form->addElement(new Zend_Form_Element_Submit(array(
            'name' => 'Submit',
        )));
        
        $this->view->form = $form;
        
         if ($this->getRequest()->isPost()) {
            if (!$form->isValid($_POST)) {
                echo "Error";
            } else {
                Zend_Debug::dump($form->getValues()); //Problem is HERE!
            }
        }

Posted by Thomas Weidner (thomas) on 2008-10-13T11:54:30.000+0000

Probably fixed with r11936.

Posted by Martin Hujer (mhujer) on 2008-10-13T11:59:53.000+0000

It shows "Warning: Invalid argument supplied for foreach() in Zend\Form\Element.php on line 524" now :-)

<pre class="highlight">
line 524:
foreach ($this->getFilters() as $filter) {
            $value = $filter->filter($value);
        }

You should probably return some array.

Posted by Thomas Weidner (thomas) on 2008-10-13T12:00:42.000+0000

What should getValues() be for a function ? File Elements do not have a value !!!

Calling this method on file elements will return unexpected values.

Posted by Martin Hujer (mhujer) on 2008-10-13T12:09:15.000+0000

patch:

<pre class="highlight">
Index: Zend/Form/Element/File.php
===================================================================
--- Zend/Form/Element/File.php  (revision 11936)
+++ Zend/Form/Element/File.php  (working copy)
@@ -354,7 +354,10 @@
     public function getFilters()
     {
         $adapter = $this->getTransferAdapter();
-        return $adapter->getFilters($this->getName());
+        $filters = $adapter->getFilters($this->getName());
+       if (!is_array($filters)) {
+           return array();
+       }
     }
 
     /**

Posted by Martin Hujer (mhujer) on 2008-10-13T12:19:51.000+0000

Sorry, the right patch:

<pre class="highlight">
Index: Zend/Form/Element/File.php
===================================================================
--- Zend/Form/Element/File.php  (revision 11937)
+++ Zend/Form/Element/File.php  (working copy)
@@ -354,7 +354,11 @@
     public function getFilters()
     {
         $adapter = $this->getTransferAdapter();
-        return $adapter->getFilters($this->getName());
+        $filters = $adapter->getFilters($this->getName());
+        if (!is_array($filters)) {
+            $filters = array();
+        }
+        return $filters;
     }
 
     /**

Posted by Thomas Weidner (thomas) on 2008-10-13T12:56:00.000+0000

Should now work with r11939

Posted by Goran Juric (gog) on 2008-11-12T17:39:27.000+0000

I can confirm that this works for me now! Finally :)

Thanks...

Posted by Wil Sinclair (wil) on 2008-11-13T14:10:26.000+0000

Changing issues in preparation for the 1.7.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts