I have put on user register form some profile fields. And if the user gets an error message from validation, the user picture disapears, and the user is registered without picture!
I fixed the problem.
In the module script you must change the 'validate' case to handle if not exist picture:
case 'validate':
// validate uploaded picture, taken from user module
$validators = array(
'file_validate_is_image' => array(),
'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024),
);
$file = file_save_upload('picture_upload_register', $validators);
if (!$file){form_set_error('reg_with_pic','No picture!!!');}
break;
Comments
Comment #1
mmilano commentedThe problem I have with this is that it will make the picture field required.
Comment #2
mmilano commentedOk, I came up with a solution.
I added some onchange JS to the file form element which sets a flag if the user has selected a picture.
If there are no form errors, then the image will upload.
If there are form errors, and the user has selected a picture, then they will be presented with a reminder to reselect a picture.