Thomas,

here is an exemple of what I'm taking about (modified version of your blog post :) ) :

require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
$request = new Zend_Controller_Request_Http(); // setup the form
$form = new Zend_Form();
$form->setMethod("post");
$form->setAttrib("enctype",Zend_Form::ENCTYPE_MULTIPART);
// file element, upload is optional, but if file is uploaded run multiple validators
$file1 = $form->createElement("file","file1");
$file1->setRequired(false)
      ->setLabel("File:")
->addValidator('Count', true, 2) ->addValidator('Size', true, "100KB")
      ->addValidator('Extension', true, 'jpg')
      ->addValidator('MimeType',true,array('image/jpeg'))
      ->addValidator('ImageSize',true,array(0,0,340,480))
      ->setMultiFile(3);
$comment = $form->createElement("text","comment"); $form->addElements(array($file1,$comment)); // check the form
if($request->isPost()) {
   $formData = $request->getPost();
   if($form->isValid($formData)) {
       echo "FORM VALID";
   } else {
print_r($form->getMessages()); }
} else {
   // It's over symplified here
   $data = array('comment'=>'initial value');
   $form->populate($data);
   $formData = (object) $form->getValues();
}


?>

<form method="post" enctype="multipart/form-data">
 <input name="fichier" type="file1" />
 <input name="comment" type="text" value="<?= $formData->comment ?>" />
 <input name="envoyer" type="submit" value="envoyer" />
</form>

Laurent Melmoux a écrit :
Hi Thomas,

Well I said $_FILES to simplified the internal of Zend_File_Transfer_Adapter_Abstract which is using Zend_File_Transfer_Adapter_Abstract ::_files :) sorry if it made it confusing.

To simplified it :

If I call Zend_Form::getValues() before any form submission an exception is thrown ("myFile" not found by file transfer adapter ) which occur in Zend_File_Transfer_Adapter_Abstract :: _getFiles() because it can not find the element in _files


Right now I’m using the patch below (which is making use of the $noexception arg to avoid the exception) and it is working ok:


Zend_Form_Element_File::getValue()
// @line 643
$content = current($this->getTransferAdapter()->getFileInfo($this->getName(), true));

And

Zend_File_Transfer_Adapter_Abstract
// @line 886
public function getFileInfo($file = null, $noexception = false)
{
       return $this->_getFiles($file, false, $noexception);
}


Thomas Weidner a écrit :
Laurent,

getValues does NOT access $_FILES.
This you have misunderstood. The $_FILES array is used as input for the transfer adapter. But again, it does not work with the $_FILES array. The internal representation of the data is different to $_FILES.

So you said that you are not displaying the form but do this yourself.
As long as you are following the syntax of the HTTP file element it should work. But when you use subforms or multifiles and are not using the file decorator you must do the normalisation manually.

This exception you are referring to does simply say:
The file element you requested is not defined, nor is it a filename or a temporary name... I don't know which data you want to work with.

As you gave no details it's hard to say something specific to this problem.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Laurent Melmoux" <[EMAIL PROTECTED]>
To: "Zend Framework General" <fw-general@lists.zend.com>
Sent: Wednesday, December 03, 2008 3:01 PM
Subject: [fw-general] Zend_Form + Zend_File_Transfer issue with Zend_Form::getValues()


Hi guys, Matthew, Thomas,

I’m giving a try to Zend_Form + Zend_File_Transfer and I’m facing a issue with Zend_Form_Element_File::getValue()

I’m not using Zend_Form to renders my forms.
Before displaying the form (on create or update) I populate it with default values or values from the db and then I’m using Zend_Form::getValues() to pass form values to the view.

But here with files element Zend_Form_Element_File::getValue() try to access the global $_FILES and as no form has been submitted yet an exception thrown :

throw new Zend_File_Transfer_Exception(sprintf('"%s" not found by file transfer adapter', $find));

See :
Zend_File_Transfer_Adapter_Abstract ::getFileInfo($file = null)
Zend_File_Transfer_Adapter_Abstract ::_getFiles($files, $names = false, $noexception = false)

Is it a issue or am I using incorrectly Zend_Form + Zend_File_Transfer ?

Regards,

--
Laurent Melmoux
Conseil et Solutions Web | [EMAIL PROTECTED]
2mx - Annecy, France | http://laurent.2mx.fr/





--
Laurent Melmoux
Conseil et Solutions Web | [EMAIL PROTECTED]
2mx - Annecy, France     | http://laurent.2mx.fr/
Tél.                     | +33 (0)9 74 53 10 40

Reply via email to