You are here

function imagepicker_copy_form_validate in Image Picker 7

Same name and namespace in other branches
  1. 6.2 imagepicker.functions.inc \imagepicker_copy_form_validate()

Function to validate the copy form

File

./imagepicker.functions.inc, line 2715
@author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function imagepicker_copy_form_validate($form, &$form_state) {
  if (!drupal_strlen($form_state['values']['imagepicker_copy'])) {
    form_set_error('imagepicker_copy', t('You must supply a name'));
  }
  elseif (!preg_match('/^[a-zA-Z0-9_ .-]+$/', $form_state['values']['imagepicker_copy'])) {
    form_set_error('imagepicker_copy', t('You must supply a valid name'));
  }
  if (isset($form_state['values']['uid'])) {
    $user = user_load($form_state['values']['uid']);
  }
  else {
    global $user;
  }
  $img_id = $form_state['values']['img_id'];
  $img = _imagepicker_get_img($img_id, TRUE, $user);
  preg_match('/\\.([a-zA-Z]+)$/', $img->img_name, $m);
  $oldext = $m[1];
  preg_match('/\\.([a-zA-Z]+)$/', $form_state['values']['imagepicker_copy'], $m);
  $newext = $m[1];
  if ($oldext != $newext) {
    form_set_error('imagepicker_copy', t('You must use the same extension'));
  }
  if ($img->img_name == $form_state['values']['imagepicker_copy']) {
    form_set_error('imagepicker_copy', t('You cannot copy a file onto itself'));
  }
  if (drupal_strlen($form_state['values']['scale']) && (!is_numeric($form_state['values']['scale']) || $form_state['values']['scale'] < 1)) {
    form_set_error($name, t("Scale value should be an integer greater than 0 or leave it empty if you don't want to scale your image."));
  }
}