The form API says that the #required property is not allowed for file elements - there's a patch out there that allows the property and places an asterisk next to the label as desired when it is set to 'TRUE', but it still doesn't actually validate for the presence of an uploaded file. I'd like to write a custom validation function, but the file validation functions all seem to apply only in the case where a file has already been uploaded. Can anybody help me write a custom validation function to make a file upload field required?? This is my attempt that doesn't work:
function mymodule_user_register_validate($form_id, $form_values, &$form){
if (count($_FILES)==0) {
form_set_error('picture_upload_register', t('PROB'));
}
}
Comments
Comment #1
thesubtledoctor commentedI tried an idiot test - adding a function to the validators array of the file_save_upload function that always returns an error message - see below. It didn't work. Any ideas why this could be?
Comment #2
XerraX commentedi just did this, seems to work... i am not a pro
just dont know how to get the red star to the field...
Comment #3
mmilano commentedI added an admin settings page where you can select if the field is required or not. Also the form logic to support a required field.
Comment #5
kenorb commentedhttp://drupal.org/node/271476