function imagepicker_upload_form_validate in Image Picker 5
Same name and namespace in other branches
- 5.2 imagepicker.module \imagepicker_upload_form_validate()
- 6.2 imagepicker.upload.inc \imagepicker_upload_form_validate()
- 7 imagepicker.upload.inc \imagepicker_upload_form_validate()
Validate form
File
- ./
imagepicker.module, line 199 - Enables permitted roles to upload images for insertion into configured nodes.
Code
function imagepicker_upload_form_validate($form_id, $form_values) {
foreach ($form_values as $name => $value) {
$value = trim($value);
switch ($name) {
case 'file_upload':
if (empty($_FILES['files']['name']['file_upload'])) {
form_set_error($name, t('Image file field is required.'));
}
elseif (!isset($_FILES['files']['tmp_name']['file_upload']) || !file_exists($_FILES['files']['tmp_name']['file_upload'])) {
form_set_error($name, t('Error while uploading file.'));
}
elseif (!image_get_info($_FILES['files']['tmp_name']['file_upload'])) {
form_set_error($name, t('Uploaded file is not an image.'));
}
elseif (!imagepicker_get_uploaded_file_extension('file_upload')) {
form_set_error($name, t('Only .jpg, .gif and .png image files are accepted.'));
}
break;
case 'thumb':
if (!preg_match('/^[0-9]{1,3}$/', $value) || $value <= 0) {
form_set_error($name, t('Thumbnail size should be an integer between 1 and 999.'));
}
break;
case 'scale':
if (!preg_match('/^[0-9]{0,3}$/', $value)) {
form_set_error($name, t('Scale value should be an integer between 1 and 999 or leave it empty if you don\'t want to scale your image.'));
}
break;
}
}
}