Zend Framework

Zend_Form_Element_File does not work without filters

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.7 Preview Release
  • Fix Version/s: 1.7.0
  • Component/s: Zend_Form
  • Labels:
    None

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

Activity

Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Martin Hujer added a comment -

Problem is with $form->getValues()

$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!
            }
        }
Show
Martin Hujer added a comment - Problem is with $form->getValues()
$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!
            }
        }
Hide
Thomas Weidner added a comment -

Probably fixed with r11936.

Show
Thomas Weidner added a comment - Probably fixed with r11936.
Hide
Martin Hujer added a comment -

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

line 524:
foreach ($this->getFilters() as $filter) {
            $value = $filter->filter($value);
        }

You should probably return some array.

Show
Martin Hujer added a comment - It shows "Warning: Invalid argument supplied for foreach() in Zend\Form\Element.php on line 524" now
line 524:
foreach ($this->getFilters() as $filter) {
            $value = $filter->filter($value);
        }
You should probably return some array.
Hide
Thomas Weidner added a comment -

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

Calling this method on file elements will return unexpected values.

Show
Thomas Weidner added a comment - What should getValues() be for a function ? File Elements do not have a value !!! Calling this method on file elements will return unexpected values.
Hide
Martin Hujer added a comment -

patch:

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();
+		}
     }
 
     /**
Show
Martin Hujer added a comment - patch:
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();
+		}
     }
 
     /**
Hide
Martin Hujer added a comment -

Sorry, the right patch:

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;
     }
 
     /**
Show
Martin Hujer added a comment - Sorry, the right patch:
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;
     }
 
     /**
Hide
Thomas Weidner added a comment -

Should now work with r11939

Show
Thomas Weidner added a comment - Should now work with r11939
Hide
Goran Juric added a comment -

I can confirm that this works for me now! Finally

Thanks...

Show
Goran Juric added a comment - I can confirm that this works for me now! Finally Thanks...
Hide
Wil Sinclair added a comment -

Changing issues in preparation for the 1.7.0 release.

Show
Wil Sinclair added a comment - Changing issues in preparation for the 1.7.0 release.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
Not Specified
Original Estimate - Not Specified
Remaining:
0m
Remaining Estimate - 0 minutes
Logged:
1h
Time Spent - 1 hour