Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-28-2008, 05:02 PM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default Zend_Form_Element_File and Zend_File_Transfer problem

I was up till 04:00 this morning going mad over this problem, so I hope someone can help.

The first one should be simple. I'm trying to create a custom error message for an empty file form element:
PHP Code:
$cv = new Zend_Form_Element_File('cv');
$cv->setLabel('Upload CV')
   ->
setRequired(true)
   ->
setAutoInsertNotEmptyValidator(false)
   ->
addValidator('NotEmpty'true, array('messages'=>'- please upload your CV'))
   ->
addValidator('Count'false1);     // ensure only 1 file 
However, when the file field is left empty, the following default error messages are shown:
Code:
    * The file 'cv' was not uploaded
    * Value is empty, but a non-empty value is required
What am I doing wrong here?

The second problem is the main one driving me crazy.
if I fill in the whole form so it's valid, when it comes to moving the uploaded file via "$adapter->receive()", I get this message:
Code:
["fileUploadErrorAttack"] => string(51) "The file 'cv' was illegal uploaded, possible attack"
This is the code in the controller:
PHP Code:
// Get form
$form = new ApplicationForm();
$this->view->form $form;    

// Get request object
$request $this->getRequest();        
        
// Check if we have a POST request
if (!$request->isPost()) {
    return;
}

// Get form data
$formData $request->getPost();

// Validate form
if (!$form->isValid($formData)) {
    
// Invalid entries
    
$this->view->formError true;
    
    
// Log failure
    
$this->logger->setEventItem('action''Application Form Invalid');
    
$message 'Job ' $jobId ' was applied for:' PHP_EOL print_r($formDatatrue)
             . 
PHP_EOL 'IP Address:' $_SERVER['REMOTE_ADDR'];
    
$this->logger->info($message);
                    
    return 
$this->render('details'); // re-render the application form
}    

// Valid form
// Move uploaded file
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($this->config->cvdir);


if (!
$adapter->receive()) {
    
Zend_Debug::Dump($adapter);
    
Zend_Debug::Dump($adapter->getMessages());
    exit;
}

// Handle the file ready for sending as an email attachment... 
I also tried using:
PHP Code:
if (!$form->cv->receive()) {
    print 
"Error receiving the file";
    exit;

but I get this message:
Code:
exception 'Zend_Form_Element_Exception' with message 'Method receive does not exist' in 
C:\xampp\php\library\ZendFramework-1.6.1\library\Zend\Form\Element.php:911 Stack trace: #0 [internal function]: Zend_Form_Element->__call('receive', Array) #1
C:\xampp\htdocs\rgac.co.uk\application\default\controllers\JobController.php(175): Zend_Form_Element_File->receive() #2 
C:\xampp\php\library\ZendFramework-1.6.1\library\Zend\Controller\Action.php(502): JobController->detailsAction() #3
C:\xampp\php\library\ZendFramework-1.6.1\library\Zend\Controller\Dispatcher\Standard.php(293): Zend_Controller_Action->dispatch('detailsAction') #4 
C:\xampp\php\library\ZendFramework-1.6.1\library\Zend\Controller\Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #5
C:\xampp\htdocs\rgac.co.uk\public_html\index.php(65): Zend_Controller_Front->dispatch() #6 {main}
I'm using ZF1.6.1 and Xampp on Vista, but this problem occurs on my Linux hosting server too.

Am I doing something wrong here?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 09-29-2008, 07:15 AM
Member
 
Join Date: Aug 2008
Posts: 67
Default

There is a simple reason...
Translating error messages does not work for the file transfer component with 1.6.1.

Simply use SVN trunk and you will succeed.
__________________
Greetings
Thomas Weidner
I18N Team Leader, Zend Framework
http://www.thomasweidner.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-29-2008, 09:26 AM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default

Quote:
Originally Posted by thomas View Post
There is a simple reason...
Translating error messages does not work for the file transfer component with 1.6.1.

Simply use SVN trunk and you will succeed.
Thanks Thomas.
Will "$form->cv->receive()" work with the latest code in trunk?
Any idea when the next stable version will be released?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-29-2008, 11:57 AM
Member
 
Join Date: Aug 2008
Posts: 67
Default

I know as much as you but I think it's expected between 3 weeks and Christmas
__________________
Greetings
Thomas Weidner
I18N Team Leader, Zend Framework
http://www.thomasweidner.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-29-2008, 12:04 PM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default

Quote:
Originally Posted by thomas View Post
I know as much as you but I think it's expected between 3 weeks and Christmas
Do you mean 3 weeks+ for "$form->element->receive()" to work, or for the next release?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 09-29-2008, 12:07 PM
Member
 
Join Date: Aug 2008
Posts: 67
Default

Release...

receive() is already implemented in the element since about 2 weeks.
__________________
Greetings
Thomas Weidner
I18N Team Leader, Zend Framework
http://www.thomasweidner.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-29-2008, 12:15 PM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default

Right, I'll download the latest code via SVN later and test it out.

Thanks again Thomas...great component!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 10-16-2008, 02:52 PM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default

I now have 1.6.2 installed, and receive() works fine. However, I still cannot manage to set a custom error message if a file is not uploaded.
Here's my code:
PHP Code:
$cv = new Zend_Form_Element_File('cv');
$cv->setLabel('Upload CV')
   ->
setDestination('C:\upload')
   ->
setRequired(true)
   ->
addValidator('NotEmpty'false, array('messages'=>'- please upload your CV')); 
Am I missing something?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 10-16-2008, 03:05 PM
Member
 
Join Date: Aug 2008
Posts: 67
Default

I don't know Zend_Form in detail... it's not my component ... but my understanding is that translating messages works different.
__________________
Greetings
Thomas Weidner
I18N Team Leader, Zend Framework
http://www.thomasweidner.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 10-16-2008, 03:49 PM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default

Quote:
Originally Posted by thomas View Post
I don't know Zend_Form in detail... it's not my component ... but my understanding is that translating messages works different.
Do you mean there might be a different way to customise messages for Zend_Form_Element_File? That would be strange. I'll ask around on that one.

Quick Question
If I don't want to keep the uploaded file, how can I get the temporary filename via your component? For example, after validating the form, I want to attach the uploaded file to an email, then I no longer need it.

I'd normally use something like this:
PHP Code:
$fileArray $formArray['file'];
if (
$fileArray['error'] == UPLOAD_ERR_OK) {
    
// Upload OK, so continue            
    // Prepare CV attachment
    
$fileContents file_get_contents($fileArray['tmp_name']);
    
$attachment $mail->createAttachment($fileContents);
    
$attachment->type $fileArray['type'];
    
$attachment->filename $fileArray['name'];

What's the best way to do this now with your code?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:08 AM.