setRequired() doesnt seem to be working on file element

1 message Options
Embed this post
Permalink
gbhumphrey

setRequired() doesnt seem to be working on file element

Reply Threaded More More options
Print post
Permalink
Ok, I have a file element for a form. I'm trying to get it to throw a error when no file is selected.
I have setRequired(), but no error is thrown. setRequired() defaults to true.
I also have an Extension validator, which does get thrown WHEN there is a file, and it's the wrong file type.
Note that I never see my custom message, but rather the default error for the Extension validation.

Errors are thrown when file is attached, but not when they are not.
[code]
$this->_formElements = array(
 'account_file' => $this->createElement('file', 'account_file')
  ->setLabel('File: ')
  ->setRequired()
  ->addValidator('Extension', false, 'jpg,png,gif,psd')
  ->addErrorMessage('you need a file'),
                       
  'submit' => $this->createElement('submit', 'Save', array('value' => 'Click to Upload', 'class' => 'fileFormButton'))
                );
[/code]

So do you have to have a file attached, for setRequired() to be considered?

thanks