0
votes

I created a stand alone zend form for uploading files and I set the file element as a required field. But the file element is not printing out any error message.

I set the decorators for the file element like so:

// The file element requires the File decorator instead of the 
// ViewHelper decorator
$file->setDecorators(array(
    'File',
    'Errors',
)); 

I pasted the code here: http://pastebin.com/0D59pxiR

I pasted the template here: http://pastebin.com/SRYh71JN

What am I doing wrong? I thank you in advance for your assistance.

2

2 Answers

0
votes

you may need to split the ispost and the isvalid:

if( isset( $_POST['submit'] )) {
    if ($form->isValid( $_POST )){
    echo 'Thank you';
    }
    //if is post but not valid reload page and render the errors
    echo $form->render( $view );//render form with errors
    echo $form->getMessages($view);//or just render the messages back to the view
} else {
    echo $form->render( $view );//if not post render form
}

This is my best guess.

[Edit]

have you tried

$file->addDecorator('File');

instead of

$file->setDecorators(array(
    'File',
    'Errors',
));

The form level setElementDecorators maybe somehow interferring with setting the file element decorators. addDecorator() or addDecorators() should prevent that.

I would also suggest you try using the default decorators for test to rule out any other potential issues.

I don't see anything obvious. The only thing that's really different is that the File element proxies isValid() to Zend_File_Transfer. I suppose there could be an issue there, but if there were I would expect a significant error message.

0
votes

Needed to print out enctype="element->getEnctype();?> and everything worked.